java Joda-Time,没有日期的时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15459001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 19:40:34  来源:igfitidea点击:

Joda-Time, Time without date

javajodatime

提问by Jedi Knight

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 ?

我想要一个只存储时间而不是日期或日期的类。Joda-Time 有这方面的课程吗?还是我必须使用日期时间并仅将时间部分转换为字符串然后使用该部分?

回答by Bozho

There's the LocalTimeclass for that purpose.

LocalTime这个目的的类。

Read more about partials here. E.g.:

在此处阅读有关部分的更多信息。例如:

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

回答by Rahul Tripathi

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

LocalTime- 表示没有日期的时间的不可变类(无时区)

Check out this

看看这个

回答by Stephan

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

从 JodaTime 2.0 开始,也可以像这样实例化一个没有日期的时间:

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

回答by Mordechai

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

Java 8 现在有自己的LocalTime类。不需要外部库。