码迷,mamicode.com
首页 > 其他好文 > 详细

计算两个日期时间之间的时间差:28小时38分钟

时间:2017-01-22 23:49:24      阅读:447      评论:0      收藏:0      [点我收藏+]

标签:puts   ref   on()   log   out   href   时间   htm   target   

<script src="moment.min.js"></script>

var now = "04/09/2017 13:59:59";
var then = "02/09/2017 14:20:30";
var ms = moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss"));
var d = moment.duration(ms);
var s = Math.floor(d.asHours()) + moment.utc(ms).format(":mm:ss");
console.log(s)
// outputs: "48:39:30"

var then = moment().format(‘YYYY-MM-DD HH:mm:ss‘);
setInterval(function(){
var now = moment().format(‘YYYY-MM-DD HH:mm:ss‘);
var ms = moment(now,"YYYY-MM-DD HH:mm:ss").diff(moment(then,"YYYY-MM-DD HH:mm:ss"));
var d = moment.duration(ms);
var h = Math.floor(d.asHours());
var m = moment.utc(ms).format("mm");
$("p").html(h+‘小时‘+m+‘分钟‘);
},60000)
// outputs: "0小时00分钟"

setInterval(function(){
var now = moment().format(‘YYYY-MM-DD HH:mm:ss‘);
// console.log(then)
// console.log(now)
var ms = moment(now,"YYYY-MM-DD HH:mm:ss").diff(moment(then,"YYYY-MM-DD HH:mm:ss"));
var d = moment.duration(ms);
var h = Math.floor(d.asHours());
var m = moment.utc(ms).format("mm");
var s = moment.utc(ms).format("ss");
// var s = Math.floor(d.asHours()) + moment.utc(ms).format(":mm:ss");
$("div").html(s+‘秒‘);
},1000)
// outputs: "01秒"

链接:http://codego.net/6837891/

计算两个日期时间之间的时间差:28小时38分钟

标签:puts   ref   on()   log   out   href   时间   htm   target   

原文地址:http://www.cnblogs.com/cxying93/p/6341575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!