How I can get the client timezone using moment-timezone.js or moment.js ?
Thanks!
How I can get the client timezone using moment-timezone.js or moment.js ?
Thanks!
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?
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.