JodaTime gets current milliseconds since the beginning of the day

I am trying to get the current milliseconds from the beginning of this day. Therefore, I would like to make the following calculation. 86400000-currMilliSecondsFromBeginningOfDay. Any help would be greatly appreciated. Thanks

+5
source share
2 answers
long result = new DateTime().millisOfDay().getMillis();  

or

long result = new DateTime().getMillis() - new DateTime().withMillisOfDay(0).getMillis();  

or

long result = new LocalTime().get(DateTimeFieldType.millisOfDay());
+10
source

You can get the start of the day using DateMidnight from the jodatime library.

long todayStart = new DateMidnight().getMillis();

While the DateTime constructor will set the current value of the millis field.

+1
source

All Articles