1
     $scope.formatDate = function formatDate(dateString) {

                var dString = new Date(dateString);  
                return dString;
     }

dateString='2020-03-14 06:48' is of string type.

working for chrome/firefox but not for IE/Safari

Output

For Safari/IE-Invalid date

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Diya Rawat
  • 33
  • 7
  • 1
    what is value you are passing to `formatDate()` function? – Prasad Telkikar May 14 '20 at 12:42
  • 1
    You tagged it as c# but i guess you mean JavaScript? What's the value of `dateString` and what exactly means "not working"? An example with input and expected and actual result would help. – Christoph Lütjen May 14 '20 at 12:43
  • Did you check if console reported an error? - https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh968260(v%3Dvs.85) - https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/samples/gg589530(v=vs.85) – Rand Random May 14 '20 at 12:48
  • You should use this date format: **dateString='2020/03/14 06:48'**. This is the valid format in IE. Or you could use the date formats in [this page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse) which are RFC2822 or ISO 8601 formatted date. – Yu Zhou May 15 '20 at 02:15

1 Answers1

0

According to compatibility table Date ctor should be working for IE/Safari

Please make sure you are passing valid dateString

A string value representing a date, specified in a format recognized by the Date.parse() method. (These formats are IETF-compliant RFC 2822 timestamps, and also strings in a version of ISO8601.)

Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50
  • '2020-03-14 06:48' is not consistent with the format supported by [ECMA-262](http://ecma-international.org/ecma-262/10.0/#sec-date-time-string-format) so parsing is implementation dependent. – RobG May 15 '20 at 03:19