I'm trying to display a clock that updates every second (e.g. 1/5/2015 12:05:01 then 1/5/2015 12:05:02, etc.) using 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.
Can someone advise?
it seems to work fine for me. For the same code. And only the moment.min.js pointed to v2.11.0
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);
});
Working fiddle with v2.11.0 - JSFiddle Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With