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

后端 未结 3 1798
遇见更好的自我
遇见更好的自我 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:22

    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

提交回复
热议问题