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

后端 未结 3 1762
遇见更好的自我
遇见更好的自我 2021-01-18 03:45
DateTimeFormatter fmt = DateTimeFormat.forPattern(\"HH:mm:ss\");
LocalTime localTime = fmt.parseLocalTime(\"02:51:20\");
System.out.println(\"LocalTime:            \         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 04:16

    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));
    

提交回复
热议问题