Parse clock time in java 8

后端 未结 1 1104
死守一世寂寞
死守一世寂寞 2020-12-19 10:07

I wonder is it possible to parse clock time hour:minute:second in Java 8?

e.g.

final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"HH:m         


        
相关标签:
1条回答
  • 2020-12-19 10:47

    LocalTime.parse

    Since you only have a time use the LocalTime class. No need to define a formatting pattern in your case.

    String str = "12:22:10";
    LocalTime time = LocalTime.parse(str);
    

    See that code run live at IdeOne.com.

    See Oracle Tutorial for more info.

    0 讨论(0)
提交回复
热议问题