jquery从字符串转换为时间 [英] jquery convertion from string to time
本文介绍了jquery从字符串转换为时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个正在开发的系统,它按以下格式记录一天中的不同时间:
06:53:22 或 19:23:58 作为示例。
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.
有人能告诉我是否可以将此字符串转换为javascript构造,我可以使用它来比较当天的时间吗?
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];
}
它返回00:00:00以来的秒数,所以你可以轻松比较结果:
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')
这篇关于jquery从字符串转换为时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文