Reputation: 581
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 ?
Upvotes: 17
Views: 17128
Reputation: 16184
Java 8 now has its own LocalTime class. No need for an external library.
Upvotes: 0
Reputation: 43013
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") //
);
Upvotes: 0
Reputation: 172378
LocalTime
- Immutable class representing a time without a date (no time zone)
Check out this
Upvotes: 4
Reputation: 597016
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");
Upvotes: 30