I need to write a function that accepts java.util.Dateand removes hours, minutes and milliseconds from it. USING JUST MATH (without date formats, without Calendar objects, etc.) :
private Date getJustDateFrom(Date d) {
}
The purpose of this method is to get a date from a millisecond value without time.
Here is what I still have:
private Date getJustDateFrom(Date d) {
long milliseconds = d.getTime();
return new Date(milliseconds - (milliseconds%(1000*60*60)));
}
The problem is that it only removes minutes and seconds. I do not know how to remove a watch.
If I do milliseconds - (milliseconds%(1000*60*60*23)), then he returns to 23:00 the previous day.
EDIT:
Here's an alternative solution:
public static Date getJustDateFrom(Date d) {
Calendar c = Calendar.getInstance();
c.setTime(d);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
return c.getTime();
}
Will this decision depend on time zone differences between the client and server sides of my application?