我在项目上使用momentJS实时(计数时间)时钟。并且运行良好。这是我的代码:
interval = setInterval(function() {
momentNow = moment();
moment_time = momentNow.format('hh:mm:ss A');
moment_date = momentNow.format('MMMM DD, YYYY') + ' '
+ momentNow.format('dddd')
.substring(0,3).toUpperCase();
// displays the time
real_time.html(moment_time);
real_date.html(moment_date);
}, 1000);
像任何人一样,我希望从插件中获得更多。我想显示从间隔
momentNow = 02:22:30 PM
开始的特定时间的计数时间。基本上,逻辑是这样的
伪代码:
interval = setInterval(function() {
var started = "02:22:30 PM";
rendered_time.html(started);
}, 1000);
最佳答案
您想要的是moment.diff(timestamp)
范例程式码
timestamp = moment().now()
setInterval(function() {
rendered_time.html(moment(moment().diff(timestamp)).format("hh:mm:ss A"));
});
http://momentjs.com/docs/#/displaying/difference/
关于javascript - 如何使用MomentJS从特定时间开始计数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37130785/