JavaScript new Date

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Call new Date() for now, new Date(ms) for a timestamp, or new Date(string) to parse (prefer ISO strings). Avoid relying on non-ISO parse formats.

JavaScript Syntax

JavaScript
const now = new Date();
console.log(now instanceof Date);
const epoch = new Date(0);
console.log(epoch.toISOString());
Try it Editor

How It Works

  1. new Date(). Current time.
  2. new Date(0). Unix epoch.

Examples

Example 1 — ISO string

Reliable parse.

JavaScript
console.log(new Date("2020-01-02T00:00:00.000Z").toISOString());
Try it Editor

How It Works

  1. Prefer ISO-8601.

Example 2 — Y/M/D components

Month is 0-based.

JavaScript
const d = new Date(2020, 0, 2);
console.log(d.getFullYear(), d.getMonth(), d.getDate());
Try it Editor

How It Works

  1. January is month 0.

Frequently Asked Questions

Temporal is the modern API. Use Date when you need wide support today.
Only ISO-8601 is consistently reliable across engines.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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