0

I have date in the format

06-Feb-2013

But when i pass this date through function new Date() like

 var dateSample = "06-Feb-2013";
 var d = new Date(dateSample);
 alert(d);

I am getting different outputs in Chrome and Firefox like.

Chrome
Chrome alert

Firefox
Firefox alert

How to make my date format work in firefox also.?
I can't change the date format.
If the solution is in native Javascript, it will be good.
please help me?

Sandeep
  • 1,504
  • 7
  • 22
  • 32
  • Possible duplicate of [new Date() is working in Chrome but not Firefox](http://stackoverflow.com/questions/3257460/new-date-is-working-in-chrome-but-not-firefox) – JJJ Mar 04 '16 at 10:50

1 Answers1

0

Slashes (/) are more widely supported then hyphens (-):

new Date("06/Feb/2013")
-> Date 2013-02-06T00:00:00.000Z

If you cannot hardcode the change from hyphens to dashes, you can simply replace them:

new Date("06-Feb-2013".replace(/-/g, '/'));
-> Date 2013-02-06T00:00:00.000Z
James Donnelly
  • 126,410
  • 34
  • 208
  • 218