I need help figuring out how to convert a Javascript date object to UTC, assuming a timezone like America/New_York
:
2019-01-04T00:00:00.000Z
The desired result is to convert this to a date object in UTC
.
2019-01-04T05:00:00.000Z
const timezone = 'America/New_York';
const localMidnight = new Date(Date.UTC(2019, 0, 4)) // 2019-01-04T00:00:00.000Z
moment.tz(localMidnight, timezone).utc().toDate()
Despite the efforts, the function is still returning the same value as the input date 2019-01-04T00:00:00.000Z
.
> m(localMidnight, 'America/New_York').tz('utc').toDate()
2019-01-04T00:00:00.000Z
> m(localMidnight, 'America/New_York').tz('UTC').toDate()
2019-01-04T00:00:00.000Z
> m(localMidnight, 'America/New_York').utc().toDate()
2019-01-04T00:00:00.000Z