3 ms·
The by-integers constructor accepts overflow on any of the input values and adjusts accordingly: > new Date(2015,10,30) Mon Nov 30 2015 00:00:00 GMT+
by dspillett 11y ago
The by-integers constructor accepts overflow on any of the input values and adjusts accordingly:
> new Date(2015,10,30)
Mon Nov 30 2015 00:00:00 GMT+0000 (GMT Standard Time)
> new Date(2015,10,31)
Tue Dec 01 2015 00:00:00 GMT+0000 (GMT Standard Time)
> new Date(2015,10,32)
Wed Dec 02 2015 00:00:00 GMT+0000 (GMT Standard Time)
> new Date(2015,10,320)
Thu Sep 15 2016 00:00:00 GMT+0100 (GMT Daylight Time)
> new Date(2015,10,01,23,59)
Sun Nov 01 2015 23:59:00 GMT+0000 (GMT Standard Time)
> new Date(2015,10,01,23,590)
Mon Nov 02 2015 08:50:00 GMT+0000 (GMT Standard Time)
- Xophmeister 11y agoI can kind of justify that, insofar as it's unlikely that any input would be entered directly like that and it has the quite nice property of allowing date arithmetic on an arbitrary unit (e.g., "+ 1 calendar month, 4 hours and 25 milliseconds", etc.)
- dspillett 11y agoYes, I've deliberately used it that way in the past: newDate = new Date(refDate.getFullYear(), refDate.getMonth(), refDate.getDate(), refDate.getHours()+1000, refDate.getMinutes()) letting it deal with the wrapping of larger date/time parts as needed.