Silviu Fuicu
Silviu Fuicu

Reputation: 51

How to auto convert on user TimeZone using moment.js

I have this format date:

Sunday 20:30 America/Toronto

i want every time a user access the page with the date to get auto timezone convert that date but i only want to convert and display for example this format Sunday 20:30 .

thanks in advance.

Upvotes: 2

Views: 660

Answers (1)

engma
engma

Reputation: 1969

You can you use moment-timezone alongside with timeZoneDetect and this will get the desired behaviour.

For example:

var tz = jstz.determine();
var userTimeZone = tz.name();
//you can use any date format here you want
var currentTime    = moment.tz("2014-06-01 12:00", "America/Toronto"); // time defined in Toronto timezone
var userTime = newYork.clone().tz(userTimeZone);

Upvotes: 1

Related Questions