使用moment.js查找两次之间的时差 [英] Find time difference between 2 times using moment.js
本文介绍了使用moment.js查找两次之间的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到2次(HH:MM:SS格式)之间的差异.
I have a requirement to find the difference between 2 times(times in HH:MM:SS) format.
需要以秒为单位的差异.
Need to get the difference in seconds.
var a = moment('21:04:59');
var b = moment('21:04:00');
a - b = 59 seconds
我尝试了以下 它对我来说适用于日期时间格式,但不是单独提交时间.
I have tried following Its worked for me with date time format, but not time filed alone.
var a = moment('2016-06-06T20:30:59');
var b = moment('2016-06-06T20:30:00');
console.log(a.diff(b, 'seconds')) // 59 seconds
推荐答案
您必须像在moment
var a = moment({
h: 21,
m: 04,
s: 59
});
var b = moment({
h: 21,
m: 04,
s: 00
});
输出
console.log(a.diff(b, 'seconds'))
// 59秒
这篇关于使用moment.js查找两次之间的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文