使用 moment.js 更新提供的时间

Update the time provided using moment.js

我有一个函数,可以从数据库中获取 utc 时间,例如“2015-10-28T18:02:44”,我想使用 moment.js 中的设置间隔更新时间 这样它给我的输出就像 8:02:53 am 一样,一秒钟后 8:02:54 am 就像普通时钟一样。 到目前为止,我的代码似乎不起作用

function update() {
    var date = moment(new Date("2015-10-28T18:02:44"));
    console.log(date.format('h:mm:ss a'));
};

setInterval(function(){
    update();
}, 1000);

获取更新函数前的日期,在里面加一秒然后格式化。

var date = moment.utc("2015-10-28T18:02:44").local();

function update() {
    console.log(date.add(1, "s").format('h:mm:ss a'));
};

setInterval(function(){
    update();
}, 1000);

JSFiddle

确保 setInterval 设置为 1000 (1s)