Date.parse() converts a date string into milliseconds since the Unix epoch. This guide covers syntax, ISO 8601 best practices, validation, time-difference math, and how it compares to new Date(string).
01
Syntax
Date.parse(str)
02
Static
On Date
03
ISO 8601
Best format
04
Invalid
Returns NaN
05
vs new Date
Same ms
06
Validate
Number.isNaN
Fundamentals
Introduction
APIs, forms, and JSON payloads often deliver dates as strings. Before you compare, sort, or subtract them, you need a numeric timestamp. Date.parse() is a static method that performs that conversion in one step.
It returns epoch milliseconds (like Date.now()) or NaN when the string cannot be parsed. For many workflows, new Date(string) is equally fine—but Date.parse() is handy when you only need the number.
Concept
Understanding the Date.parse() Method
Date.parse(dateString) is a static method on the Date constructor. It does not create a Date object; it returns the parsed instant as a number of milliseconds since January 1, 1970 00:00:00 UTC.
For valid ISO 8601 strings, results are consistent across modern browsers and Node.js. Ambiguous formats like 03/04/2025 may parse differently depending on implementation—prefer explicit ISO strings in production.
💡
Beginner Tip
Date.parse(str) is equivalent to new Date(str).getTime() when the string parses successfully. Use Number.isNaN(Date.parse(str)) to catch bad input.
Foundation
📝 Syntax
JavaScript
Date.parse(dateString)
Parameters
dateString — A string representing a date and time (ISO 8601 recommended).
Return value
Number of milliseconds since the Unix epoch for a parseable string.
NaN if the string cannot be parsed into a valid instant.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Parse ISO string to ms
Date.parse("2026-03-15T12:00:00.000Z")
Build Date from string
new Date(Date.parse(str)) or new Date(str)
Check valid parse
!Number.isNaN(Date.parse(str))
Elapsed between strings
Date.parse(end) - Date.parse(start)
Same as getTime()
new Date(str).getTime()
Human UTC output
new Date(ms).toISOString()
Compare
📋 Date.parse() vs Similar APIs
These APIs all involve strings and timestamps but serve different jobs.
Date.parse()
str → ms
Static parse
new Date(str)
Date obj
Object wrapper
Date.now()
now ms
Current time
toISOString()
Date → str
Opposite direction
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it links. ISO strings ending in Z parse as UTC for predictable results.
📚 Getting Started
Convert an ISO 8601 string into epoch milliseconds.
Example 1 — Parse an ISO 8601 Date String
UTC strings ending in Z are the most portable format.
Choose Date.parse when you only need the number; choose new Date when you will call getters or formatters on the result.
Applications
🚀 Common Use Cases
API payloads — convert ISO date strings from JSON to numbers.
Form validation — reject unparseable date input before submit.
Sorting events — parse strings then compare numerically.
Duration math — subtract two parsed timestamps.
Deadline checks — compare Date.parse(deadline) to Date.now().
Migration scripts — batch-convert string columns to epoch ms.
🧠 How Date.parse() Converts a String
1
Receive string
You pass a date string to the static parse method.
Input
2
Engine parse
JavaScript interprets the format (ISO is most reliable).
Parse
3
Map to instant
A single UTC instant is identified internally.
Instant
4
🔢
Return ms or NaN
Epoch milliseconds on success; NaN if parsing fails.
Important
📝 Notes
Prefer ISO 8601 strings (e.g. 2026-03-15T12:00:00.000Z) for cross-environment consistency.
Invalid input returns NaN—validate with Number.isNaN(Date.parse(str)).
Ambiguous formats like 01/02/2023 may parse differently by engine or locale.
Date.parse(str) === new Date(str).getTime() for successful parses.
For display, convert ms back with new Date(ms).toISOString() or locale formatters.
Date.parse does not throw—always check the return value.
Compatibility
Browser & Runtime Support
Date.parse() has been available since ES1. ISO 8601 strings parse consistently in all modern browsers and Node.js.
✓ Baseline · ES1
Date.parse()
Supported everywhere. Stick to ISO 8601 for predictable parsing across Chrome, Firefox, Safari, Edge, and Node.js.
99%Universal API
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Date.parse()Excellent
Bottom line: Safe everywhere. Prefer ISO strings and validate with Number.isNaN before using parsed values.
Wrap Up
Conclusion
Date.parse() turns date strings into epoch milliseconds for comparison, sorting, and duration math. Use ISO 8601 input, validate with Number.isNaN, and pair with new Date(ms) or toISOString() for object workflows.
Next, learn toDateString() for readable local date labels, or use toISOString() to serialize dates back to UTC strings.
Use ISO 8601 strings with explicit timezone (Z or offset)
Validate with Number.isNaN(Date.parse(input))
Subtract parsed timestamps for elapsed time
Store epoch ms in databases for easy sorting
Convert back with toISOString() for logs
❌ Don’t
Trust ambiguous MM/DD/YYYY strings without tests
Assume parse throws on bad input
Use loose isNaN("foo") for string validation
Forget to check parse result before arithmetic
Mix unparsed strings in numeric comparisons
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Date.parse()
Your foundation for string-to-timestamp conversion in JavaScript.
5
Core concepts
📝01
Syntax
Date.parse(str)
API
📄02
ISO
Best input.
Format
🔢03
Epoch ms
Return value.
Unit
⚠04
NaN
Bad input.
Validate
⇄05
new Date
Same ms.
Compare
❓ Frequently Asked Questions
The number of milliseconds since the Unix epoch for the parsed date string, or NaN if the string cannot be parsed into a valid instant.
Date.parse() returns the epoch milliseconds directly. new Date(string) returns a Date object. For valid strings, Date.parse(str) equals new Date(str).getTime().
ISO 8601 strings such as 2026-03-15T12:00:00.000Z are the most reliable across browsers and Node.js. Ambiguous formats like 01/02/2023 may parse differently by locale.
Check Number.isNaN(Date.parse(input)). A failed parse returns NaN—not an error or exception.
No. It returns NaN for unparseable strings. Always validate the result before using it in calculations or UI.
No. Date.now() returns the current timestamp. Date.parse() converts an existing date string into a timestamp.
Did you know?
Date.parse("2026-03-15T12:00:00.000Z") and new Date("2026-03-15T12:00:00.000Z").getTime() return the same milliseconds—parse skips creating a Date when you only need the number.