johnjay22113 johnjay22113 - 5 months ago 13
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

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")
Comments