I have a system in development which records various times of the day in the following format: 06:53:22 or 19:23:58 as examples.
Can anyone tell me if it is possible to convert this string into javascript construct which I can use to compare times of the day?
You can parse the time with this:
function timeToSeconds(time) {
time = time.split(/:/);
return time[0] * 3600 + time[1] * 60 + time[2];
}
It returns a number of seconds since 00:00:00, so you can compare the results easily:
timeToSeconds('06:53:22') < timeToSeconds('19:23:58')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With