JavaScript Date parse() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Static · string → ms

What You’ll Learn

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

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.

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.

📝 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.

⚡ Quick Reference

GoalCode
Parse ISO string to msDate.parse("2026-03-15T12:00:00.000Z")
Build Date from stringnew Date(Date.parse(str)) or new Date(str)
Check valid parse!Number.isNaN(Date.parse(str))
Elapsed between stringsDate.parse(end) - Date.parse(start)
Same as getTime()new Date(str).getTime()
Human UTC outputnew Date(ms).toISOString()

📋 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

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.

JavaScript
const iso = "2026-03-15T12:00:00.000Z";
const timestamp = Date.parse(iso);

console.log("Timestamp (ms):", timestamp);
Try It Yourself

How It Works

The result is a large integer you can subtract, compare, or pass to new Date(ms). Always validate before using user-provided strings.

📈 Practical Patterns

Date objects, validation, duration math, and API comparison.

Example 2 — Create a Date from a Parsed Timestamp

Turn the numeric result back into a Date for formatting or getters.

JavaScript
const iso = "2026-03-15T12:00:00.000Z";
const date = new Date(Date.parse(iso));

console.log(date.toISOString()); // "2026-03-15T12:00:00.000Z"
Try It Yourself

How It Works

new Date(iso) alone works too—use Date.parse when you need the number first or want to validate before constructing a Date.

Example 3 — Validate User Date Input

Failed parses return NaN. Check before storing or displaying.

JavaScript
function isValidDateString(input) {
  return !Number.isNaN(Date.parse(input));
}

console.log(isValidDateString("2026-03-15T12:00:00.000Z")); // true
console.log(isValidDateString("not-a-date"));               // false
Try It Yourself

How It Works

Date.parse never throws on bad input—it returns NaN. Number.isNaN is the reliable check (avoid loose isNaN on strings).

Example 4 — Calculate Time Between Two Date Strings

Parse both strings, subtract timestamps, and convert to hours.

JavaScript
const start = Date.parse("2026-03-15T12:00:00.000Z");
const end = Date.parse("2026-03-15T14:30:00.000Z");

const hours = (end - start) / (1000 * 60 * 60);
console.log("Hours between:", hours); // 2.5
Try It Yourself

How It Works

Subtracting parsed timestamps gives elapsed milliseconds. Divide by the right factor for seconds, minutes, or hours.

Example 5 — Compare Date.parse() and new Date()

For valid strings, both paths yield the same epoch milliseconds.

JavaScript
const iso = "2026-03-15T12:00:00.000Z";

const fromParse = Date.parse(iso);
const fromDate = new Date(iso).getTime();

console.log("Date.parse:", fromParse);
console.log("getTime():", fromDate);
console.log("Equal:", fromParse === fromDate);
Try It Yourself

How It Works

Choose Date.parse when you only need the number; choose new Date when you will call getters or formatters on the result.

🚀 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.

📝 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.

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 Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.parse() Excellent

Bottom line: Safe everywhere. Prefer ISO strings and validate with Number.isNaN before using parsed values.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.parse()

Your foundation for string-to-timestamp conversion in JavaScript.

5
Core concepts
📄 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.

Continue to toDateString()

Format parsed timestamps as readable local calendar date strings.

toDateString() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful