JSFiddle - React, Tailwind, and code Playground
by Andrea Forni
HTML
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<script src="http://momentjs.com/downloads/moment-timezone-with-data.js"></script>
<script src="http://visavie.me/test/js/jquery.datetimepicker.js"></script>
<link rel="stylesheet" href="http://visavie.me/test/css/jquery.datetimepicker.css">
time in chicago based on localtimezone:
<div id="time"></div>
<br>time in chicago based on timestamp from the server:
<div id="time2"></div>
JavaScript
function updateTime() {
var chicago = moment.tz("America/Chicago").format('h:mm:ss A');
$('#time').html(chicago + ", ");
};
moment.tz.add('America/Chicago|CST CDT|60 50|01010101010101010101010|1BQU0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0');
updateTime();
setInterval(function () {
updateTime();
}, 1000);
function updateTimeBasedOnServer(timestamp) {
var Chicago = moment(timestamp);
var dateString = Chicago.format('h:mm:ss A');
$('#time2').html(dateString + ", ");
};
var timestamp = 1443618723;
updateTimeBasedOnServer(timestamp);
setInterval(function () {
timestamp += 1000;
updateTimeBasedOnServer(timestamp);
}, 1000);