MozenRath MozenRath - 11 months ago 85
Java Question

How to get date part (dispose of time part) from java.util.Date?

I want to compare the date part of two

objects. How can I achieve this? I am not looking to comparing the date, month and year separately.

Thanks in advance!

Answer Source

A Date is just an instant in time. It only really "means" anything in terms of a date when you apply a calendar and time zone to it. As such, you should really be looking at Calendar, if you want to stick within the standard Java API - you can create a Calendar object with the right Date and time zone, then set the time components to 0.

However, it would be nicer to use Joda Time to start with, and its LocalDate type, which more accurately reflects what you're interested in.