I'm trying to create a UTC date from an array of values. The documentation states that if any of the parameters are omitted it should default to 0 or 1.
Syntax:
Date.UTC(year, month[, day[, hour[, minute[, second[, millisecond]]]]])
Example:
var tp = [2019]
var d = new Date(Date.UTC.apply(null, tp))
console.log(d.toString())
Result: "Invalid Date"
Example #2:
var tp = [2019, 01]
Result: "Thu Jan 31 2019 18:00:00 GMT-0600 (CST)"
Expected: "Thu Jan 1 2019 00:00:00 GMT-0600 (CST)"
Could somebody explain what's happening here?
Update:
I should clarify that I was using the API as MDN states. The issue was that Safari does not have an up to date implementation. This was verified with the help of another SO user, who fortunately updated the documentation.
The second example came from a misunderstanding that .toISOString()
was zero-indexed, whereas it produces values with a timezone offset of 0, not that the months are zero-indexed.
ES5ES2016, so Example #1’s *Invalid Date* could have come from an old environment. – Ry- Jan 13 '19 at 15:14