troubleshooting Question

Best way to remove time from a Date object in Java

Avatar of kpbarem
kpbarem asked on
JavaProgrammingJava EE
7 Comments1 Solution68 ViewsLast Modified:
I have a method that is comparing a Date passed in to see if it is on or after today (fairly simple).  So I create a Date object and initialize it with default constructor, which gives me the current Date and time.  

if(dateParam.after(today) || dateParam.equals(today)) does not return the correct result if the date passed in is today.  This is because the default date constructor gives me the current date but also the current time.  So therefore if the param is 8/21/2014 and today is 8/21/2014 16:55:00:00 then these two are not equal.

What is the best way to ensure that it just compares the date portion and not the time portion?  Is there a way to zero out the time on a date object? Or possibly a method that doesn't consider the time in comparison?

Thanks in advance for your help!!
ASKER CERTIFIED SOLUTION
dpearson

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros