I\'m trying to find out how I can display dynamic date and time using moment.js.
Apparently I can\'t figure out to use setInterval properly.
If possible I\'d pre
Again, thanks for your answers. The code I ended up with follows. (Note danish i18n)
moment.lang('da');
var datetime = null, date = null;
var datetime_update = function() {
date = moment(new Date());
datetime.html(date.format('[Lige nu: ] ffffdd [d.] Do MMMM YYYY [kl.] HH:mm:ss'));
};
$(document).ready(function() {
datetime = $('#datetime');
datetime_update();
setInterval(datetime_update, 1000);
});
EDIT: Here nine months after I asked this quesiton I figured out this way to do it without jQuery (as I initially asked). Here it is:
function date_time() {
now = moment().format('ffffdd [d.] Do MMMM YYYY [kl.] HH:mm:ss');
document.getElementById('timer').innerHTML = now;
setTimeout(function () { date_time(); }, 1000);
}
date_time();
And then of course use it with an HTML ID like: