问题
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