JavaScript Date & Timestamp Converter
Convert between JavaScript Date objects, Unix timestamps, and human-readable date strings. Paste any timestamp or ISO 8601 date string to decode it instantly.
JavaScript Timestamp and Date Conversion
JavaScript's Date object uses millisecond timestamps internally. This converter translates between Unix timestamps (seconds), JS timestamps (milliseconds), ISO 8601 strings, and local date/time representations.
- JS timestamp โ date: Convert
Date.now()output to a readable string - Unix timestamp โ JS: Convert server-side second timestamps to JS milliseconds
- ISO 8601 โ timestamp: Parse date strings like
2024-01-15T10:30:00Zto a numeric value - Timezone display: See both UTC and local time for any input
JavaScript Date Quick Reference
- Current ms timestamp:
Date.now()โ returns milliseconds since epoch, nonewneeded - Current seconds timestamp:
Math.floor(Date.now() / 1000) - Timestamp to Date object:
new Date(msTimestamp)โ pass ms directly; multiply seconds by 1000 first - Date to ISO string:
new Date().toISOString()โ"2024-01-15T10:30:00.000Z" - Parse ISO string:
new Date("2024-01-15T10:30:00Z").getTime()โ milliseconds - Format for display:
new Date().toLocaleString("en-US", { timeZone: "America/New_York" })
Common JavaScript Date Pitfalls
- Seconds vs. milliseconds:
new Date(1700000000)gives January 20, 1970 (treating it as ms) โ you wantnew Date(1700000000 * 1000)for a Unix second timestamp - Month is 0-indexed:
new Date(2024, 0, 15)is January 15 โ month 0 = January, month 11 = December - Date string parsing is implementation-dependent:
new Date("2024-01-15")is parsed as UTC midnight;new Date("01/15/2024")is parsed as local time โ prefer ISO 8601 with explicit timezone - DST transitions: When doing date arithmetic across DST boundaries, use UTC methods (
getUTCHours,setUTCDate) to avoid off-by-one-hour bugs
Frequently Asked Questions
Why does JavaScript use milliseconds instead of seconds?
JavaScript's Date object was designed in 1995 to match Java's java.util.Date, which also uses milliseconds. The millisecond resolution was a deliberate choice to support sub-second timing for animations and UI interactions โ common browser use cases that don't require a server. Most server-side systems (Unix, databases) use seconds because sub-second precision wasn't needed when those standards were set in the 1970s.
What is the best way to work with dates in JavaScript?
For simple cases, the native Date object with Intl.DateTimeFormat is sufficient. For complex date arithmetic (business day calculations, timezone-aware scheduling, duration formatting), use the Temporal API (available in modern browsers as of 2024โ2025) or a library like date-fns (tree-shakeable, immutable) or dayjs (Moment.js-compatible, small). Avoid Moment.js in new projects โ it's in maintenance mode and not tree-shakeable.
How do I store timestamps in a database from JavaScript?
For PostgreSQL, store as TIMESTAMPTZ (timestamp with time zone) and pass ISO 8601 strings: new Date().toISOString(). For MySQL, use DATETIME with UTC storage and convert on read. For flexibility and portability, many developers store Unix timestamps as BIGINT (milliseconds) โ avoids timezone handling in the database entirely, at the cost of less readable values in direct SQL queries.