Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is getLocalMillis() of LocalTime in Joda Time is a protected method?

Tags:

java

jodatime

I wanted to convert joda time LocalTime to millis or milliseconds. I saw that the getLocalMillis is a protected method. Looks like there is no method to get the millis value of LocalTime.

So, do I have to get the values of each field in millis and then add them up to get the total millis ? Why does Joda Time not have a public method for getting Local Millis ?

like image 954
Jedi Knight Avatar asked Mar 20 '13 02:03

Jedi Knight


People also ask

Is Joda-time deprecated?

So the short answer to your question is: YES (deprecated).

Does Joda datetime have time zones?

An interval in Joda-Time represents an interval of time from one instant to another instant. Both instants are fully specified instants in the datetime continuum, complete with time zone.

What is Joda-time API?

Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.

What is Joda LocalDate?

LocalDate is an immutable datetime class representing a date without a time zone. LocalDate implements the ReadablePartial interface. To do this, the interface methods focus on the key fields - Year, MonthOfYear and DayOfMonth.


2 Answers

A LocalTime does not represent an absolute instant in time, but rather it describes a time of any day for an arbitrary timezone.

Render your LocalTime into an DateTime via LocalTime#toDateTimeToday() or LocalTime#toDateTimeToday(DateTimeZone) if you're looking for the moment described by that time today. Or if you want that moment on another day, construct the appropriate LocalDate and see the LocalDate#toDateTime(...) methods. Then call DateTime#getMillis().

like image 200
cheeken Avatar answered Oct 17 '22 09:10

cheeken


You can use also .toDate().getTime()

like image 43
Nickolay Savchenko Avatar answered Oct 17 '22 10:10

Nickolay Savchenko