I would like to get the current date with the time zeroed out in milliseconds.
Example, if it's 12:69pm today, I want to get the time in milliseconds for today's date with no time...meaning, the time just after midnight (one millisecond or 0 if that works).
I was using the Calendar object but can't seem to figure out how to zero out the time portion.
Here is how to zero the time of a calendar:
Calendar today = Calendar.getInstance();
today.set(Calendar.MILLISECOND, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.HOUR_OF_DAY, 0);
And without calendar:
long d = new Date().getTime();
int offset = TimeZone.getDefault().getOffset(d);
d = ((d + offset)/ 86400000l) * 86400000l - offset;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With