Skip to content

Instantly share code, notes, and snippets.

@trfiladelfo
Created July 6, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trfiladelfo/af254ba0de1f159bb6498cc3f34478f7 to your computer and use it in GitHub Desktop.
Save trfiladelfo/af254ba0de1f159bb6498cc3f34478f7 to your computer and use it in GitHub Desktop.
utilizando datas e timezone em javascript
moment.min.js
moment-timezone-with-data-2010-2020.min.js
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>
$(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