Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joda-Time, Time without date

Tags:

java

jodatime

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 ?

like image 545
Jedi Knight Avatar asked Mar 17 '13 08:03

Jedi Knight


People also ask

Is Joda time deprecated?

So the short answer to your question is: YES (deprecated).

What is Joda time format?

Joda-Time provides a comprehensive formatting system. There are two layers: High level - pre-packaged constant formatters. Mid level - pattern-based, like SimpleDateFormat.

Is Joda time included in Java 8?

Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.


2 Answers

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");
like image 144
Bozho Avatar answered Nov 02 '22 19:11

Bozho


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

Check out this

like image 32
Rahul Tripathi Avatar answered Nov 02 '22 19:11

Rahul Tripathi