2

I would like to convert "2020-09-07T00:52:26.000Z" to 07-09-2020 14:22:26, but I was not getting the desired time while conversion.

Conversion needed: Asia/Kolkata to Asia/Hong_Kong

I tried:

const moment = require('moment-timezone');
var momentmm = moment("2020-09-07T00:52:26.000Z").utc();
var updatetimezone = moment.tz(momentmm, 'Asia/Hong_kong').format();
console.log("1. After Convert timezone", updatetimezone)

Result: 1. After convert timezone 2020-09-07T08:52:26+08:00

var str = moment("2020-09-07T00:52:26.000Z").tz('Asia/Hong_kong').utc().format('DD-MM-YYYY HH:mm:ss');
console.log("2. After Convert timezone", str)

Result: 2. After convert timezone 07-09-2020 00:52:26

Desired Result:

07-09-2020 14:22:26

James Z
  • 12,209
  • 10
  • 24
  • 44
Aldo
  • 158
  • 1
  • 10
  • `00:52:26.000Z` => `07-09-2020 14:22:26` - that would require a timezone that is `UTC+13:30` - is that the timezone you're in? – Jaromanda X Sep 10 '20 at 05:06
  • Z means UTC or Greenwich timezone +00:00 – Anatoly Sep 10 '20 at 05:07
  • also, since you want `Conversion needed: Asia/Kolkata to Asia/Hong_Kong` - there's no reference to `Asia/Kolkata` in your code, and I doubt the difference between those two zones is 13.5 hours either – Jaromanda X Sep 10 '20 at 05:09
  • ```var str = moment("2020-09-07T00:52:26.000Z").format('DD-MM-YYYY HH:mm:ss ZZ'); console.log(str)``` it gives my location time ```07-09-2020 06:22:26 +0530``` , i.e IST (UTC +5:30) – Aldo Sep 10 '20 at 05:28

1 Answers1

1
var on = new Date("2020-09-07T00:52:26.000Z");
var m = moment(on)
var str = moment(m).format('DD-MM-YYYY HH:mm:ss ZZ');
console.log(str)
console.log("Converted timezone", moment.tz(str, 'Asia/Hong_Kong').format('DD-MM-YYYY HH:mm:ss'))

That will do it..

Wolf
  • 116
  • 9