johnjay22113 johnjay22113 - 1 year ago 108
jQuery Question

Dynamically convert timestamp to a different timezone

I am using moment.js and moment-timezone. how can I create a function to convert

2016-06-12 06:22:18
UTC time to the user's timezone time and then format the time to
Jun 12, 2015 6:22 PM

for example:

updateTime("2016-06-12 06:22:18");

if in chicago, the output will be:

"Jun 12, 2016, 1:22 AM"

Answer Source

You can try something like this.

moment.utc("2016-06-12 06:22:18", "YYYY-MM-DD HH:mm:ss").tz('America/Chicago').format("MMM D, YYYY, hh:mm a")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download