Created
September 1, 2017 13:05
-
-
Save lloydjatkinson/9760d08e5651222639fea15f499a87b8 to your computer and use it in GitHub Desktop.
moment.js + moment-timezone.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
<h3>Converting current time</h3> | |
<div> | |
UTC: <span class="align" id="utc"></span> | |
</div> | |
<div> | |
London: <span class="align" id="london"></span> | |
</div> | |
<div> | |
Paris: <span class="align" id="paris"></span> | |
</div> | |
<div> | |
New York: <span class="align" id="new-york"></span> | |
</div> | |
<h3>Converting an instant</h3> | |
<div> | |
UTC: <span id='some-utc-instant'></span> | |
<span id='friendly'></span> | |
</div> | |
<div> | |
New York: <span id='some-local-instant'></span> | |
</div> | |
setInterval(renderTime, 1000); | |
function renderTime() { | |
// Troubleshooting: https://maggiepint.com/2016/05/14/moment-js-shows-the-wrong-date/ | |
var utc = moment().utc(); | |
$('#utc').text(utc); | |
$('#london').text(moment.tz(utc, 'Europe/London')); | |
$('#paris').text(moment.tz(utc, 'Europe/Paris')); | |
$('#new-york').text(moment.tz(utc, 'America/New_York')); | |
var someDate = moment('2017-06-30T23:30:00+01:00'); | |
$('#some-utc-instant').text(someDate); | |
$('#some-local-instant').text(moment.tz(someDate, 'America/New_York')); | |
$('#friendly').text('This was ' + someDate.from(utc)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment