Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to Joda LocalTime format (HH:mm:ss) and Remove milliseconds

Tags:

java

jodatime

DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm:ss");
LocalTime localTime = fmt.parseLocalTime("02:51:20");
System.out.println("LocalTime:            "+localTime);

I need only 02:51:20 but it outputs as 02:51:20.000. Is there any way that I can remove the .000 (milliseconds) from the output.

like image 696
souashokraj Avatar asked Jan 16 '15 17:01

souashokraj


1 Answers

Yes - you just need to format when you print out. Currently you're just using the default toString() representation. If you're happy with the formatter you've already got, you can just use:

System.out.println("LocalTime:            " + fmt.print(localTime));
like image 73
Jon Skeet Avatar answered Sep 23 '22 06:09

Jon Skeet