I had a problem when I wanted to compare two dates. However, I wanted to compare the year, month, and day. And this is what I can handle:
private Date trim(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR, 0); return calendar.getTime(); }
I use this function to trim all blocks, but days, months and years.
Now the question is, what do you think of this? Do you know any other way to do this?
thanks
java date
Adelin
source share