mega6382 mega6382 - 3 years ago 184
Javascript Question

How do I parse this illogical date string in javascript?

I have a date time string

September 30, 2017 @ 11:23 am
, which is parsable in chrome using:

var end = new Date("September 30, 2017 @ 11:23 am");


But in firefox it gives
invalid date
error. How do I parse it in Firefox?

Answer Source

According to MDN

String value representing a date. The string should be in a format recognized by the Date.parse() method

Source

Solution: You can simply remove @ from the stirng. using replace method or any other way.

Ex:

var d = "September 30, 2017 @ 11:23 am"
var end = new Date(d.replace("@",""));

console.log(end)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download