Safari: ‘a.getTime’ is undefined

Recently, we were working with Google Charts at which we were presenting data from a timeline with some processing.
Our JavaScript code was formatted as follows to create Date objects:

$value = "2020-03-19 23:45:00";
var dateStrFormat = new Date($value);

The above code worked fine on Firefox and Chrome but it failed on Safari with the error:
a.getTime is not a function. (In 'a.getTime()', 'a.getTime' is undefined)
After some investigation we found that Safari does not support a Date() constructor that contains time as well so we had to change the code to the following block:

var dateStr = "2020-03-19";
var dateStrFormat = new Date(dateStr);
var hourStr = "23";
var minutesStr = "45";
dateStrFormat.setHours(hourStr, minutesStr);

The above works on all browsers!

This post is also available in: Αγγλικα


Αυτός ο ιστότοπος χρησιμοποιεί το Akismet για να μειώσει τα ανεπιθύμητα σχόλια. Μάθετε πώς υφίστανται επεξεργασία τα δεδομένα των σχολίων σας.