Created
July 6, 2020 16:26
-
-
Save trfiladelfo/af254ba0de1f159bb6498cc3f34478f7 to your computer and use it in GitHub Desktop.
utilizando datas e timezone em javascript
This file contains hidden or 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
moment.min.js | |
moment-timezone-with-data-2010-2020.min.js |
This file contains hidden or 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
UTC<br/> | |
<div id="divUTC"></div><br/> | |
Your Local Time with respect to above UTC time<br/> | |
<div id="divLocal"> | |
</div> | |
<br/>Thailand date time<br/> | |
<div id="divThai"> | |
</div> | |
<br/>America date time<br/> | |
<div id="divUsa"> | |
</div> |
This file contains hidden or 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-DDTHH:mm:ss')); | |
//get text from divUTC and conver to local timezone | |
var localTime = moment.utc(divUtc.text()).toDate(); | |
localTime = moment(localTime).format('YYYY-MM-DDTHH:mm:ss'); | |
divLocal.text(localTime); | |
$('#divThai').text(moment.tz('Asia/Bangkok').format('YYYY-MM-DD HH:mm:ss')); | |
$('#divUsa').text(moment.tz('America/Los_Angeles').format('YYYY-MM-DD HH:mm:ss')); | |
},1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment