Moment.js动态更新时间(以秒为单位) [英] Moment.js dynamically update time in seconds

查看:1298
本文介绍了Moment.js动态更新时间(以秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示每秒更新一次的时钟 (例如 1/5/2015 12:05: 01 ,然后 2015年1月5日12:05: 02 等),使用 moment.js .

我为我的问题找到了以前的解决方案(请参阅

I found previous solutions to my question (see Dynamic date and time with moment js and setinterval), however it doesn't work with the newest version of moment.js (v2.11.0). The solution provided uses v2.6.

有人可以建议吗?

推荐答案

对我来说似乎很好.对于相同的代码.而且只有moment.min.js指向 v2.11.0

it seems to work fine for me. For the same code. And only the moment.min.js pointed to v2.11.0

看看代码(来源:MilkyWayJoe)-

Have a look at the code(credits: to MilkyWayJoe)-

var datetime = null,
        date = null;

var update = function () {
    date = moment(new Date())
    datetime.html(date.format('dddd, MMMM Do YYYY, h:mm:ss a'));
};

$(document).ready(function(){
    datetime = $('#datetime')
    update();
    setInterval(update, 1000);
});

使用 v2.11.0 进行摆弄- JSFiddle演示

这篇关于Moment.js动态更新时间(以秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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