[英]Comparing two time strings in java
Given two strings like 02:03:45
and 10:04:20
which represents hh:mm:ss
给定两个字符串,如
02:03:45
和10:04:20
代表hh:mm:ss
Is there any efficient way to determine which is lesser and which is more?有没有有效的方法来确定哪个较小,哪个较多?
My thoughts:我的想法:
I thought of splitting them by :
and then checking.我想通过
:
将它们分开,然后检查。 But I was wondering if但我想知道是否
there is a neat way to do it有一个巧妙的方法来做到这一点
You can do it in that way:你可以这样做:
LocalTime time1 = LocalTime.parse("02:03:45");
LocalTime time2 = LocalTime.parse("10:04:20");
an then call: time1.compareTo(time2)
然后调用:
time1.compareTo(time2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.