If you have general Apache permissions, you can use DateUtils.truncate () :
Date myDate = DateUtils.truncate(myObject.getDate(), Calendar.DATE)
(If you don't have access to Apache Commons, DateUtils.truncate () is implemented basically the same as kgiannakakis answer .)
Now, if you want smart code to be very fast and you don't mind using obsolete functions from java.util.Date , here is another solution. (Disclaimer: I would not use this code myself, but I tested it, and it works even on the days when DST starts and ends.)
long ts = myObject.getDate().getTime() - myObject.getDate().getTimezoneOffset()*60000L; Date myDate = new Date(ts - ts % (3600000L*24L)); myDate.setTime(myDate.getTime() + myDate.getTimezoneOffset()*60000L);
Jenni source share