'Moment.js - how to get user time zone?
I want to set current time zone with moment.js
for user that runs my app. My problem is that many of momentjs question posted here have method called tz
but I can't see it now in 2020.
Format date in a specific timezone
With that method you can set this:
moment().tz('America/Phoeinx')
But I don't want to set this manually. I found utc
method but it returns me timezone +0000.
How to set current time zone with momentjs in 2020?
Solution 1:[1]
Ok I found an answer, all that we need is just get current utcOffset from momentjs library:
const currentUtcOffset = moment().utcOffset()
and pass it to utc
method
moment(date).utc(currentUtcOffset).toISOString()
Now everything works perfect.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |