Jquery - 获取两个日期之间的 HH:MM 格式的时间
我从两个文本字段中获取值作为日期,
var start_actual_time = $("#startPoint_complete_date").val();
var end_actual_time = $("#endPoint_complete_date").val();
现在
start_actual_time = 01/17/2012 11:20
end_actual_time = 01/18/2012 12:20
我想找出这两个日期之间 HH:MM 格式的持续时间(在本例中为 25:00) 我该怎么办...
I am getting the values from two text fields as date
var start_actual_time = $("#startPoint_complete_date").val();
var end_actual_time = $("#endPoint_complete_date").val();
which gives value
start_actual_time = 01/17/2012 11:20
end_actual_time = 01/18/2012 12:20
now i want to find out the duration in HH:MM format between these two dates (which is 25:00 in this case)
how can i do it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
请参阅演示: http://jsfiddle.net/diode/nuv7t/5/ (更改jsfiddle 中的 mootools
或打开 http://jsfiddle.net/nuv7t/564/ )
See demo : http://jsfiddle.net/diode/nuv7t/5/ ( change mootools in jsfiddle
or open http://jsfiddle.net/nuv7t/564/ )
工作示例:
给出 6:30 的警报消息
Working example:
gives alert message as 6:30
首先,我推荐这个: http://www.mattkruse.com/javascript/date/将字符串转换为日期对象,但您可以按照您想要的任何方式进行转换。转换后,您可以执行以下操作:
getTime()
函数获取自 1970/01/01 以来的毫秒数。现在您已经得到了相差的毫秒数,您可以执行任何您想要转换为更高数字的操作(例如,除以 1000 表示秒数,除以 60 表示分钟数,除以 60 表示小时数,等等)First, I recommend this: http://www.mattkruse.com/javascript/date/ to convert the string to a date object, but you can convert it any way you want. Once converted, you can do this:
The
getTime()
function gets the number of milliseconds since 1970/01/01. Now you have the number of milliseconds of difference, and you can do whatever you want to convert to higher numbers (eg. divide by 1000 for seconds, divide that by 60 for minutes, divide that by 60 for hours, etc.)我在博客上做了一些类似的事情,看看我和我的女朋友在一起多久了:P
http://daystogether.blogspot.com/ 这就是我的做法:
顺便说一句,这只是 javascript,没有jquery;)
I did something simular on a blog to see how long im together with my gf :P
http://daystogether.blogspot.com/ and this is how I did it:
BTW this is just javascript, no jquery ;)
干得好:
here you go: