简体   繁体   中英

Comparing two time strings in java

Given two strings like 02:03:45 and 10:04:20 which represents 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM