moment-timezone icon indicating copy to clipboard operation
moment-timezone copied to clipboard

This make no sense: moment(date).tz('UTC') ≠moment.tz(date,'UTC')

Open Ohar opened this issue 6 years ago • 3 comments

Description

These are not equal. It makes no sense.

moment('2018-01-01').tz('UTC').format('MM DD, YYYY') // 31 12, 2017
moment.tz('2018-01-01', 'UTC').format('MM DD, YYYY') // 01 01, 2018

Environment

Firefox Quantum 59.0.2 on Windows 10

Ohar avatar Apr 20 '18 21:04 Ohar

@Ohar It works according to the documentation https://momentjs.com/timezone/docs/#/using-timezones/

moment.tz(..., String) is used to create a moment with a time zone, moment().tz(String) is used to change the time zone on an existing moment

But I agree that it's very confusing - looks similar, but works in a different way.

ellenaua avatar Apr 25 '18 19:04 ellenaua

They have the same result for me..

paddotk avatar Oct 08 '18 12:10 paddotk

old issue, but to clarify if anyone looking:

moment('2018-01-01').tz('UTC').format('MM DD, YYYY') // 31 12, 2017

Creates a new date in current system timezone and then convert it to UTC (results may differ depending on current timezone)

moment.tz('2018-01-01', 'UTC').format('MM DD, YYYY') // 01 01, 2018

Creates a new date in UTC timezone.

dahool avatar Jul 02 '21 14:07 dahool