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 ?
Asked
Active
Viewed 1.7k times
17
-
What is the problem with this question ? If there is a genuine problem, then i will delete it. – Jedi Knight Mar 17 '13 at 08:50
-
1there's no problem, and it's a good question (+1 from me) – Bozho Mar 17 '13 at 08:51
-
@Bozho - Off topic - what do you eat ? you're just 25 and you've done so much already. I am still stuck on hello world of joda time :) – Jedi Knight Mar 17 '13 at 08:55
-
-1 from me, for a lack of research. The 5 first lines of the quick start guide of joda time, linked from its home page, give you the answer you want. – JB Nizet Mar 17 '13 at 08:55
-
@JBNizet that's another story, yes. I gave +1 because I didn't know the answer..then I found it quickly :) – Bozho Mar 17 '13 at 08:57
-
@JediKnight I started early ;) – Bozho Mar 17 '13 at 08:57
-
@JBNizet - Yes. I saw the quick start guide. Did not know it was there. I went straight to the API's. Quick start guide here - http://joda-time.sourceforge.net/quickstart.html – Jedi Knight Mar 17 '13 at 09:02
4 Answers
30
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");

Bozho
- 588,226
- 146
- 1,060
- 1,140
-
-
Since JodaTime 2.0, it's possible to use [LocalTime#parse](http://stackoverflow.com/a/28530181/363573) – Stephan Feb 15 '15 at 19:34
4
LocalTime
- Immutable class representing a time without a date (no time zone)
Check out this

Rahul Tripathi
- 168,305
- 31
- 280
- 331
0
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") //
);

Stephan
- 41,764
- 65
- 238
- 329