JavaScript Date Playground
Type a JavaScript Date expression and explore every output format and property in real time — toISOString, toString, getTime, getFullYear, and more.
The JavaScript Date object
JavaScript's built-in Date object stores time internally as the number of milliseconds since the Unix epoch (January 1, 1970 00:00:00 UTC). Every Date instance is ultimately just this single integer. The various methods — toISOString(), toString(), toLocaleString() — are different ways to display that same underlying value.
Common pitfalls when working with JavaScript dates
Several JavaScript Date behaviors trip up experienced developers:
- Months are zero-indexed: January is 0, December is 11 — always add 1 when displaying
- new Date('2024-01-01') parses as UTC midnight; new Date('2024/01/01') parses as local midnight
- new Date(2024, 0, 1) constructs January 1, 2024 in local time (month is 0-indexed)
- Date.now() returns milliseconds; Math.floor(Date.now() / 1000) gives Unix seconds
- Avoid adding days by adding 86400000ms — DST can cause this to land at the wrong time
Working with timezones in JavaScript
JavaScript's Date object has no timezone property — it is always stored in UTC. Timezone conversions are handled at display time using the Intl.DateTimeFormat API.
- new Intl.DateTimeFormat('en-US', { timeZone: 'Asia/Tokyo', dateStyle: 'full', timeStyle: 'long' }).format(date)
- date.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })
- new Intl.DateTimeFormat('en-CA', { timeZone: tz }).formatToParts(date) — returns individual parts for custom formatting
How to read the playground output
The playground shows several views of the same Date value so you can spot unit and timezone mistakes quickly. Compare getTime with Unix seconds first, then check the ISO and local strings. If the ISO date is correct but the local string looks different, the timestamp is right and only the display timezone changed.
- getTime is always milliseconds since the Unix epoch
- Unix seconds is getTime divided by 1000 and rounded down
- toISOString always displays UTC with a trailing Z
- toString and toLocaleString display in the browser's local timezone unless options override it