用jQuery进行时间减法 [英] Doing time subtraction with jQuery
本文介绍了用jQuery进行时间减法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在页面上有两个时间值:
I have two time values on a page:
8:00
22:30
我需要从22:30减去8并得到14:30.
I need to subtract 8 from 22:30 and get 14:30.
在jQuery中有直接的方法吗?如果有必要,插件对我来说很好.
Is there a straight forward way to do that in jQuery? Plug-ins are fine by me if they're necessary.
更新: 第二个数字是总数,所以也可能是
Update: The second number is a grand total so it could also be something like
48:45
我从中减去的任何东西都应该从中减去总和,而不进行任何与日期相关的计算.
Anything I subtract from it should just subtract the value from it as a total, not do any date related calculations.
推荐答案
您可以在javascript中完成它.
You can do it in javascript.
假设您有start = '8:00'
和end = '22:30'
.代码如下:
Suppose you have start = '8:00'
and end = '22:30'
. The code is as follows:
<script type="text/javascript">
var start = '8:00';
var end = '23:30';
s = start.split(':');
e = end.split(':');
min = e[1]-s[1];
hour_carry = 0;
if(min < 0){
min += 60;
hour_carry += 1;
}
hour = e[0]-s[0]-hour_carry;
diff = hour + ":" + min;
alert(diff);
</script>
最后,diff
是您的时差.
这篇关于用jQuery进行时间减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文