GVR
GVR

Reputation: 109

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.

Upvotes: 4

Views: 7845

Answers (3)

Josep Vicent Ibanez
Josep Vicent Ibanez

Reputation: 1758

This format works with Chrome, Firefox and Safari:

const epochTime = Date.parse('2020/11/24 15:30')

Upvotes: 0

Eldo.Ob
Eldo.Ob

Reputation: 794

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 :)

Upvotes: 7

S M Abrar Jahin
S M Abrar Jahin

Reputation: 14598

It is kind of odd, but a working solution for me is-

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

Upvotes: 0

Related Questions