2

Below code doesn't work with Firefox, Works perfectly fine with Chrome. Can someone please help me to find an alternate solution?

const tempDate = getStartDate['startDate']; // Returns: 2020-08-13 12:52:38
new Date(`${tempDate} UTC`);

Expected Output: Thu Aug 13 2020 08:52:38 GMT-0400 (Eastern Daylight Time)
Mitul
  • 83
  • 1
  • 5
  • 1
    You have `GMT-0400` and `UTC` in there, which one is it? `new Date(\`Wed Aug 12 2020 18:34:35 GMT-0400\`);` works as expected for me. –  Aug 19 '20 at 18:09
  • Does this answer your question? [new Date() works differently in Chrome and Firefox](https://stackoverflow.com/questions/15109894/new-date-works-differently-in-chrome-and-firefox) – gmiley Aug 19 '20 at 18:14

2 Answers2

1

You're trying to do:

new Date('2020-08-13 12:52:38 UTC')

Instead you should do:

new Date('2020-08-13T12:52:38Z')

See https://www.ecma-international.org/ecma-262/11.0/index.html#sec-date-time-string-format

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
0

maybe you can use moment: https://www.npmjs.com/package/moment

var d = new Date(`Wed Aug 12 2020 18:34:35 GMT-0400 (Eastern Daylight Time) UTC`);

var date = moment(d).utc().format()

console.log("date: ", date )
MatiasG
  • 1,140
  • 9
  • 20