Android Get current date (with time 0: 00: 000) in Milliseconds?

I would like to get the current date with zero time in milliseconds.

Example: if today is 12:69 pm, I want to get the time in milliseconds for today without time ... that is, the time immediately after midnight (one millisecond or 0 if it works).

I used the Calendar object, but I can’t figure out how to reset the time part.

+6
source share
2 answers

Here's how to zero calendar time:

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); 
+11
source

And without a calendar:

 long d = new Date().getTime(); int offset = TimeZone.getDefault().getOffset(d); d = ((d + offset)/ 86400000l) * 86400000l - offset; 
+1
source

Source: https://habr.com/ru/post/903289/


All Articles