Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date.parse() is not working in IE and FireFox

How to convert string to timestamp and date in JS. here am using Date.parse(), but its not working in IE and FF. My code is..

in chrome its working fine.

 var str = "05-Sep-2013 01:05:15 PM ";
 console.log( Date.parse( str ) );  
 console.log( Date.parse( str.replace(/-/g, '/') ) ); // 1378404315000

in IE its returns

 console.log( Date.parse( str.replace(/-/g, '/') ) ); // NaN

Please help me. thanks in advance.

like image 843
GVR Avatar asked Sep 03 '25 04:09

GVR


1 Answers

don't replace the '-' with '/', use whitespace instead.

var str = "05-Sep-2013 01:05:15 PM ";
console.log( Date.parse( str.replace(/-/g, ' ') ) );

that works for me in IE

have a look at w3schools - they're working with whitespaces :)

like image 191
Eldo.Ob Avatar answered Sep 04 '25 17:09

Eldo.Ob