[X]

How To Make Christmas Into January

luljs still works

Ask for month 12 to get December and you land in next January.

In 2026: Still works. The Date constructor numbers months from 0, so December is month 11, not 12. Passing 12 rolls over: new Date(2020, 12, 25) is the 25th of January 2021, not Christmas. Days, by contrast, start at 1. This mismatch causes countless off-by-one date bugs.

Where it came from: Date months are zero-based while days are one-based, and out-of-range months roll over, as MDN's Date constructor page shows. MDN

<script>
document.write('<p><code>new Date(2020, 11, 25)</code> is <b>' + new Date(2020, 11, 25).toDateString() + '</b> (month 11 is December)</p>');
document.write('<p><code>new Date(2020, 12, 25)</code> is <b>' + new Date(2020, 12, 25).toDateString() + '</b> (month 12 rolled into next year)</p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›