0

I want to convert the given date in a specific timezone to UTC.

I have the below date "03/26/2020 10:00 AM"

  const d = new Date(dateStr);      
  var offset = -10; //HST
  var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
  var nd = new Date(utc + (3600000 * offset));

I want the final output to be in the below format, which takes the above date and time in HST timezone and gives me UTC.

2020-01-08T16:31:00Z //This will represent UTC (8:30 PM UTC)
Thalapathy
  • 127
  • 1
  • 1
  • 12
  • 2
    https://stackoverflow.com/a/54127122/6052427 Check this please – errorau Mar 25 '20 at 06:43
  • Does this answer your question? [Convert date to another timezone in JavaScript](https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript) – Tim567 Mar 25 '20 at 06:50
  • I looked at those links, but it does not – Thalapathy Mar 25 '20 at 06:52
  • Did you try toJSON() / toISOString() methods ? Both give me 2020-03-25T22:00:00.000Z for your nd, in case you still want different few string operations or moment.js can help. – Jan Mar 25 '20 at 07:07

0 Answers0