[X]

The Dash Is UTC, The Slash Is Local

luljs 2009 still works

Swap the date separators from dashes to slashes and midnight jumps by your timezone offset.

In 2026: Every current engine parses a date-only ISO string as UTC, per the ECMAScript Date Time String Format. A slash string is not part of that format, so engines fall back to local time by convention. A browser west of UTC shows the dashed date as the previous evening, the classic 'my date is a day early' bug. The dashed form's toISOString is fixed at midnight Z, only the local rendering shifts.

Where it came from: The ECMAScript Date Time String Format (ECMA-262), where a date-only ISO string is UTC and a slash date is non-standard local time. A staple of timezone write-ups through the 2010s. MDN

<script>
var dash = new Date("2024-01-01");
var slash = new Date("2024/01/01");
document.write('<p><code>new Date("2024-01-01")</code> local: <b>' + dash.toString() + '</b></p>');
document.write('<p><code>new Date("2024/01/01")</code> local: <b>' + slash.toString() + '</b></p>');
document.write('<p>The dashed ISO date is read as UTC midnight. Its <code>.toISOString()</code> is always <b>' + dash.toISOString() + '</b>. The slashed date is read as LOCAL midnight.</p>');
document.write('<p>Gap in your timezone: <b>' + ((slash - dash) / 3600000) + '</b> hours (0 only on UTC).</p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›