i have following code manipulate time in copenhagen. wondering how able implement using js moment?
function starttime() { var today=new date(); var i=today.gethours(); var h = i-2; var m=today.getminutes(); var s=today.getseconds(); m = checktime(m); s = checktime(s); document.getelementbyid('localtime').innerhtml = h+":"+m+":"+s; var t = settimeout(function(){starttime()},500); } function checktime(i) { if (i<10) {i = "0" + i}; // add 0 in front of numbers < 10 return i; } <body onload="starttime()">
you'll need timezone plugin if want specific timezones. otherwise can leave out. provides .tz()
function starttime() { //local time document.getelementbyid('localtime').innerhtml = moment().format('hh:mm:ss'); //copenhagen timezone document.getelementbyid('copenhagen').innerhtml = moment.tz('europe/copenhagen').format('hh:mm:ss'); var t = settimeout(function(){starttime()},500); }
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment-with-locales.js"></script> <script src="http://momentjs.com/downloads/moment-timezone-with-data.js"></script> <body onload="starttime()"> <div id="localtime"></div> <div id="copenhagen"></div> </body>