Jedi Knight Jedi Knight - 11 months ago 29
Java Question

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

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 ?

Answer Source

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().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download