Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JodaTime Get Current Milliseconds From Beginning Of Day

Tags:

java

jodatime

I'm trying to get the current milliseconds from the Beginning of that day. So I would like to make the following calculation. 86400000-currMilliSecondsFromBeginningOfDay. Any help would be greatly appreciated. Thanks

like image 534
Mr. Smee Avatar asked Jun 18 '12 19:06

Mr. Smee


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());
like image 195
Ilya Avatar answered Nov 15 '22 12:11

Ilya


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

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

While DateTime constructor will set its millis field to current value.

like image 40
JBoy Avatar answered Nov 15 '22 11:11

JBoy