I am looking for a way to convert a Javascript date object in local time assuming a timezone like America/New_York
:
2019-01-04T00:00:00.000Z
I'd like 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()
Here this is still returning the same as the input 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