0

I am trying to convert date in to local time using below syntax new Date("2020-10-20 GMT+0530")

Its working in chrome but not in IE

In IE , it returning as invalid date

How to fix this in IE? Need your suggestions

Karthik Ravichandran
  • 1,205
  • 2
  • 15
  • 25
  • Have you tried approach suggested here: https://stackoverflow.com/questions/13091523/javascript-invalid-date-error-in-internet-explorer – Ananth Oct 20 '20 at 10:30
  • MDN Docs strongly discourages the use of `Date()` constructor to parse date strings. You may split input string (to extract `yyyy`, `mm`, `dd` values) and pass those as arguments to `Date()` constructor - it will be more robust. – Yevhen Horbunkov Oct 20 '20 at 10:30
  • You may refer to [this post](https://stackoverflow.com/a/63900264/11299053) as an example (it won't work *as-is* due to destructuring and arrow func syntax, but I think you may adapt that easily) – Yevhen Horbunkov Oct 20 '20 at 10:31

2 Answers2

0

IE does not support that format.
You need to supply the date string in ISO format:

new Date('2020-10-20T00:00:00-04:00')

Or like this:

new Date(year, month, day, hours, minutes, seconds, milliseconds)
domenikk
  • 1,723
  • 1
  • 10
  • 12
0

Like the person above said, not all browsers support all methods. For older browsers you need to input it in an ISO format. You cannot fix IE, unless you want to make yourself a modified version of it.