The dateToUnix()
function below is meant to return a unix timestamp given a date as the parameter (in the form of "YYYY.MM.DD").
function dateToUnix(date) {
return Math.floor(new Date(date).getTime() / 1000);
}
console.log(dateToUnix("2022.03.25")); // logs 1648180800 in Chrome
In Safari, the function returns NaN
. How can I refactor my function so that it works in both browsers?