0

How I can get the client timezone using moment-timezone.js or moment.js ?

Thanks!

medBouzid
  • 7,484
  • 10
  • 56
  • 86

2 Answers2

0

This is feature is not currently available, but is planned for a future release. See:

In the meantime, consider jsTimeZoneDetect

See also: Can I get the name of the time zone of the client by using jQuery?

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
0

Checking the issue list above, I found that detecting the user timezone is available, although it is not very very correct.

moment.tz.guess()
>> "Europe/Budapest"    // when actually I am in Madrid, but I think it is due to some historical reason

According to the discussion and having checked the src (0.5), it is based on Intl.DateTimeFormat().resolvedOptions().timeZone, and is believed to be the most corrected way, and is supported by many modern(proper) browsers, see list: https://caniuse.com/#feat=internationalization

Afortunately Budapest uses the same DST time as Madrid. If you have a target user group geographically wider distributed, I suggest more precaution to be taken.

WesternGun
  • 11,303
  • 6
  • 88
  • 157