DateTimeFormatter fmt = DateTimeFormat.forPattern(\"HH:mm:ss\");
LocalTime localTime = fmt.parseLocalTime(\"02:51:20\");
System.out.println(\"LocalTime: \
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));
Fixed this using
DateTime time = new DateTime();
DateTimeFormatter format = DateTimeFormat.forPattern("HH:mm:ss");
String localTime = time != null ? format.print(new LocalTime(time.getHourOfDay(),
time.getMinuteOfHour(), time.getSecondOfMinute())) : null;
DateTime and LocalTime are from joda
You can easily use your DateTimeFormetter print() method
. Try like this;
DateTimeFormatter fmt = DateTimeFormat.forPattern("HH:mm:ss");
LocalTime localTime = fmt.parseLocalTime("02:51:20");
System.out.println("LocalTime : " + localTime);
System.out.println("LocalTime with DateTimeFormatter : " + fmt.print(localTime));
And the output is;
LocalTime : 02:51:20.000
LocalTime with DateTimeFormatter : 02:51:20