Created
August 14, 2014 18:58
-
-
Save ktraff/394075c2b415a8c92a4f to your computer and use it in GitHub Desktop.
Convert UTC dates to local time using Moment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
setInterval(function(){ | |
var divUtc = $('#divUTC'); | |
var divLocal = $('#divLocal'); | |
//put UTC time into divUTC | |
divUtc.text(moment.utc().format('YYYY-MM-DD HH:mm:ss')); | |
//get text from divUTC and conver to local timezone | |
var localTime = moment.utc(divUtc.text()).toDate(); | |
localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss'); | |
divLocal.text(localTime); | |
},1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment