MomentJS sets the time zone without changing the time

I am trying to set the time zone for a date in moment.js without changing the time value

I get the date in utc:

date.toString() //Sun Sep 27 2015 00:00:00 GMT+0000

and I need to set the time zone without changing the time.

Sun Sep 27 2015 00:00:00 GMT-0500

if I use date.utcOffset(moment().utcOffset()), it adds an offset:

date.toString() //Sat Sep 26 2015 19:00:00 GMT-0500

I could do

date = moment(date.format("YYYYMMDDHHmmssSSSS"), "YYYYMMDDHHmmssSSSS")

but it looks like an inefficient way to do it.

Is there any method that just changes the time zone without changing the time?

+4
source share
1 answer

moment().utcOffset(0).add(moment().utcOffset(), 'minutes').format()

You will need to do some math, and without profiling there is no way to say which is the most effective.

javascript , .

+2

Source: https://habr.com/ru/post/1613706/


All Articles