Conversion from 12 hours time to 24 hours time in java

后端 未结 14 1151
失恋的感觉
失恋的感觉 2020-11-29 06:08

In my app, I have a requirement to format 12 hours time to 24 hours time. What is the method I have to use?

For example, time like 10

14条回答
  •  半阙折子戏
    2020-11-29 06:35

    Using LocalTime in Java 8, LocalTime has many useful methods like getHour() or the getMinute() method,

    For example,

    LocalTime intime = LocalTime.parse(inputString, DateTimeFormatter.ofPattern("h:m a"));
    String outtime = intime.format(DateTimeFormatter.ISO_LOCAL_TIME);
    

    In some cases, First line alone can do the required parsing

提交回复
热议问题