Joda-Time, Time without date

点点圈 提交于 2019-12-22 01:48:19

问题


I want a Class that only stores the time and not the date or day. Is there a class for this in Joda-Time ? or do I have to use a Date time and convert only the time part into a string and then use that part ?


回答1:


There's the LocalTime class for that purpose.

Read more about partials here. E.g.:

LocalTime time = new LocalTime(12, 20);
String formatted = time.toString("HH:mm");



回答2:


LocalTime - Immutable class representing a time without a date (no time zone)

Check out this




回答3:


Since JodaTime 2.0, it's also possible to instanciate a time without date like this:

LocalTime time = LocalTime.parse( //
      "12h20", //
       DateTimeFormatter.forPattern("HH'h'mm") //
);



回答4:


Java 8 now has its own LocalTime class. No need for an external library.



来源:https://stackoverflow.com/questions/15459001/joda-time-time-without-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!