Reputation: 2790
Given a Date string such as var input = '2019-09-19 13:07:09'
How can I convert that string to a different time zone? Knowing that input
is in UTC.
I tried the following:
var input = '2019-09-19 13:07:09';
var convertTo = "US/Eastern";
var dateConverted = moment.tz(input, "YYYY-MM-DD hh:mm:ss", convertTo);
dateConverted
remains the same as input
after that code is executed.
I also tried:
var input = '2019-09-19 13:07:09';
var convertTo = "US/Eastern";
var inUTC = (moment(input).utc());
var dateConverted = moment.tz(inUTC, "YYYY-MM-DD hh:mm:ss", convertTo);
But in this case, the problem is that inUTC
becomes Thu Sep 19 2019 20:07:09 GMT+0000
after (moment(input).utc());
I expect the date to be converted to EST which would be 2019-09-19 09:07:09
Any ideas how to solve this? Thanks!
Upvotes: 0
Views: 256
Reputation: 169
try this :
var input = '2019-09-19 13:07:09';
var offUtc = moment.utc(input, 'YYYY-MM-DD HH:mm:ss');
var convertTo = "US/Eastern";
var dateConverted = offUtc.clone().tz(convertTo);
Upvotes: 2