两种格式之间的差异(hh:mm:ss) [英] Difference between two times in format (hh: mm: ss)

查看:184
本文介绍了两种格式之间的差异(hh:mm:ss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两次,请说:

t1= '05:34:01' ;
t2= '20:44:44' ;

我想要两种相同格式的两次评估差异。像上述结果一样,必须来自

I want two evaluate difference between these two times in same format. Like the result of above must come as

t3= t2 - t1;  // 15:10:43 

有什么方法?

推荐答案

强烈推荐您包括 moment.js 在您的项目中,如果您需要处理时间。

Highly recommend you include moment.js in your project if you need to handle time.

示例:

var t1 = moment('05:34:01', "hh:mm:ss");
var t2 = moment('20:44:44', "hh:mm:ss");
var t3 = moment(t2.diff(t1)).format("hh:mm:ss");

工作 jsFiddle

要在 Node.js ,只需执行以下操作:

To install moment.js in Node.js, simply do:

npm install moment (或全局安装 sudo npm -g install moment

然后在你的Node .js,包括它像这样:

And then in your Node.js, include it like so:

var moment = require('moment');

编辑:对于24h时钟,更改 hh HH

Edit: For 24h clock, change hh to HH.

这篇关于两种格式之间的差异(hh:mm:ss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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