计算时差 [英] calculate time difference

查看:74
本文介绍了计算时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery时钟,给出了从00:00到23:00的时间.

I have a jQuery clock that gives the time from 00:00 to 23:00.

现在,我想计算两次之间的时间差.假设进"时间为11:00,出"时间为16:00.

Now I want to calculate the time difference between two times. Suppose the "in" time is 11:00, and the "out" time is 16:00.

如何计算javascript中的时差?

How do I calculate the time difference in javascript?

推荐答案

您可以像这样使用Date和setHours:

You can use Date and setHours like that:

var first = new Date();
first.setHours(0, 11, 0, 0);

var second = new Date();
second.setHours(0, 16, 0, 0);

alert("Diff in seconds: " + (second - first));

这篇关于计算时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆