Answers for "firefox js date parsing issue"

1

firefox js date parsing issue

// Firefox does not like the - in dateString.
// Replace all occurrences of - with / using a regular expression 
// and then convert the string to Date object.

// Method 1
let dateStr = '10-24-2021 10:14:33 AM';

// replaces all occurances of "-" with "/"
dateStr = dateStr.replace(/-/g,'/');  

var dateObject = new Date(dateStr);

// Method 2
// You can instantiate a date object in a specific way. 
// Here are some valid examples:
new Date() // current date and time
new Date(milliseconds) //milliseconds since 1970/01/01
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)
Posted by: Guest on October-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language