0

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!

chris
  • 2,490
  • 4
  • 32
  • 56
  • Possible duplicate of [Convert date to another timezone in JavaScript](https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript) – Taplar Sep 19 '19 at 20:54

1 Answers1

2

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);
N. Henoc HOUNSA
  • 169
  • 1
  • 9