0

I am using javascript Date object to parse the required date to date format e.g

 var parse = '1-3-2018 6:07 AM'
   var dateOut = new Date(parse);
   console.log(dateOut)//in mozila it shows **Invalid Date**

where as in chrome , IE it works

results are :

'Wed Jan 03 2018 06:07:00 GMT+0500 (Pakistan Standard Time)' //chrome console

'Wed Jan 03 2018 06:07:00 GMT+0500 (Pakistan Standard Time)' //opera console

'Wed Jan 03 2018 06:07:00 GMT+0500 (Pakistan Standard Time)' //IE console

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Kumail Hussain
  • 869
  • 2
  • 26
  • 49

3 Answers3

0

Firefox does not work with that format. Parse only works for specific formats for each browser. You will need to Parse the date yourself or change the format that it is passed. There are lots of ways to implement a custom date parse to reformat. Quick examples: Convert dd-mm-yyyy string to date

Josh Adams
  • 2,113
  • 2
  • 13
  • 25
0

var dateOut = new Date(2018,0,3,6,7); console.log(dateOut);

0

FireFox does not work the with that format

in chrome the below format wont work with new Date('31-12-2018 6:07 AM') //invalid date

The foolowing are the examples to worki with example

var today = new Date();

var birthday = new Date('December 17, 1995 03:24:00');

var birthday = new Date('1995-12-17T03:24:00');

var birthday = new Date(1995, 11, 17);

var birthday = new Date(1995, 11, 17, 3, 24, 0);

reference from- [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date]

Biswadev
  • 1,456
  • 11
  • 24