All Recipes
StarVerified Developer Solution • 100% Offline
Epoch / Timestamp Converter

Fix "Invalid Date" in JavaScript Date Parsing

Understand why new Date() returns Invalid Date and how to correctly parse timestamps.

The Problem (Error Root Cause)Exception

You pass a string or timestamp into `new Date()` and it evaluates to `Invalid Date`. This frequently happens when passing Unix epochs in seconds instead of milliseconds, or parsing non-ISO 8601 strings (like `YYYY-DD-MM`).

Identified via runtime validation & stack traces
The Solution (Step-by-Step Fix)Verified

JavaScript requires epoch timestamps to be in milliseconds. Multiply seconds by 1000 before passing them to the Date constructor. For strings, stick to ISO format `YYYY-MM-DDTHH:mm:ss.sssZ`.

Deterministic, non-destructive resolution

Code Standard: Bad Pattern vs Verified Fix

Live Syntax
Anti-Pattern vs Verified Fix
1// ❌ Bad: Passing seconds
2const date = new Date(1672531200); // Year 1970
3
4// ✅ Good: Passing milliseconds
5const date = new Date(1672531200 * 1000); // Year 2023

Test and resolve this using Epoch / Timestamp Converter

Execute directly in your browser memory. Zero API keys, zero network tracking, completely client-side.

Launch Epoch / Timestamp Converter

Frequently Asked Questions

Q:Why does Safari return Invalid Date but Chrome works?

Safari strictly requires ISO formats (like using "T" and "Z") whereas Chrome aggressively tries to parse irregular formats like "2023-01-01 12:00:00".

Q:How can I convert epochs manually?

Use our Epoch Converter to safely translate seconds and milliseconds to human time.

Related Troubleshooting Guides

View Directory