freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #29 of 61

date methods · format · parse · arithmetic

LambdaVSThe Mutator
Lambda saysDate methods read and format parts; arithmetic works through timestamps.

Read parts with getFullYear, getMonth, getDate, getHours, etc. Format with toISOString or, for locale-aware output, toLocaleDateString/Intl.DateTimeFormat. Date math goes through milliseconds: subtract two dates to get the gap, then divide.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleCompute the number of days between two dates via their millisecond difference.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const a=new Date(2026,0,1), b=new Date(2026,0,31);
const days=(b-a)/86400000;
document.getElementById('o').textContent=days+' days';</script></body></html>
▶ Open the interactive comic issue
‹ Dates · The Date ObjectMath · Floor · Ceil · Round · Random ›