Reputation: 508
I have a JavaScript code which is breaking in safari browser only. Here is the code..
var dateString = seldateCom.getFullYear()+"-"+month+"-"+seldateCom.getDate()+" "+$(this).val();
console.log("dateString = "+ dateString);
var date = new Date(Date.parse(dateString, "yyyy-MM-dd HH:mm:ss"));
console.log(date);
this is showing below error in safari browser console
while in Chrome it is working perfectly, here is a screenshot of Chrome browser.
What adjustment need to be done in order to work in both browsers?
Upvotes: 0
Views: 66
Reputation: 30739
Using Date.parse
will not work in safari. To get around with this you can change the code to avoid the use of it:
var dateString = "2019-3-6 05:30 pm";
var splitDate = dateString.split(/[^0-9]/);
var date = new Date(
splitDate[0],
splitDate[1]-1,
splitDate[2],
splitDate[3],
splitDate[4]
);
console.log('dateString', dateString);
console.log('date', date);
Upvotes: 1