简体   繁体   中英

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 ?

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

你也可以使用.toDate().getTime()

如果你真的需要时间毫秒,你也可以这样做:

LocalTime#get(DateTimeFieldType.millisOfDay())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM