J

JavaScript Handbook

Clean • Professional

JavaScript Date Formats

2 minute

JavaScript Date Formats

JavaScript Date objects can be created using different formats, and each format has specific behavior. Choosing the right format ensures correct parsing, consistency, and cross-browser reliability.

learn code with durgesh images

ISO Date Format (Recommended)

The ISO format is internationally recognized and is the most reliable across all browsers. It can represent just the date or date with time.

Format: YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ

Examples:

const dateOnly = new Date("2025-10-08");
console.log(dateOnly);
// Wed Oct 08 2025 00:00:00

const dateTime = new Date("2025-10-08T18:30:00");
console.log(dateTime);
// Wed Oct 08 2025 18:30:00

const dateUTC = new Date("2025-10-08T18:30:00Z");
console.log(dateUTC);
// Wed Oct 08 2025 18:30:00 GMT+0000 (UTC)

Short Date Format

This format is less reliable, especially in international contexts, because different browsers may interpret DD/MM/YYYY differently.

Format: MM/DD/YYYY or MM-DD-YYYY (mostly US-style)

Example:

const d = new Date("10/08/2025");
console.log(d);
// Wed Oct 08 2025 00:00:00

Long Date Format

Human-readable format, easy to understand. Can also include time.

Format: Month DD, YYYY

Example:

const d = new Date("October 8, 2025");
console.log(d);
// Wed Oct 08 2025 00:00:00

const d2 = new Date("October 8, 2025 18:30:00");
console.log(d2);
// Wed Oct 08 2025 18:30:00

Date and Time Format

A precise format that includes both date and time. Useful for ISO-compliant operations.

Format: "YYYY-MM-DDTHH:mm:ss"

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d);
// Wed Oct 08 2025 18:30:00

UTC Format

Represents Coordinated Universal Time (UTC). Useful for server-side or API communications.

Format: "YYYY-MM-DDTHH:mm:ssZ"

Example:

const d = new Date("2025-10-08T18:30:00Z");
console.log(d);
// Wed Oct 08 2025 18:30:00 GMT+0000 (UTC)

Milliseconds / Timestamp Format

JavaScript can create dates from raw milliseconds. Useful for calculations, comparisons, and storing dates.

Format: Milliseconds since January 01, 1970 00:00:00 UTC (Unix Epoch)

Example:

const d = new Date(1759927762375);
console.log(d);
// Wed Oct 08 2025 18:19:22

JavaScript Date Output Formats

Once a Date object is created, JavaScript provides several methods to display the date. Each method formats the date differently and can be used according to the requirement.

learn code with durgesh images

Default Output – toString()

Displays the full date and time string in the local time zone.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toString());
// Wed Oct 08 2025 18:30:00 GMT+0530 (India Standard Time)

Readable Date – toDateString()

Displays only the date in a human-readable format.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toDateString());
// Wed Oct 08 2025

Time Only – toTimeString()

Displays only the time portion of the date.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toTimeString());
// 18:30:00 GMT+0530 (India Standard Time)

UTC Date & Time – toUTCString()

Displays the date and time in UTC.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toUTCString());
// Wed, 08 Oct 2025 13:00:00 GMT

ISO String (UTC) – toISOString()

Displays the date in ISO 8601 format, always in UTC.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toISOString());
// 2025-10-08T13:00:00.000Z

Locale-Specific – toLocaleString()

Displays the date and time according to the user’s locale or a specified locale.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toLocaleString("en-US")); // US format
// 10/8/2025, 6:30:00 PM

console.log(d.toLocaleString("en-GB")); // UK format
// 08/10/2025, 18:30:00

Locale Date Only – toLocaleDateString()

Displays date only in locale-specific format.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toLocaleDateString("en-US"));
// 10/8/2025

console.log(d.toLocaleDateString("en-GB"));
// 08/10/2025

Locale Time Only – toLocaleTimeString()

Displays time only in locale-specific format.

Example:

const d = new Date("2025-10-08T18:30:00");
console.log(d.toLocaleTimeString("en-US"));
// 6:30:00 PM

console.log(d.toLocaleTimeString("en-GB"));
// 18:30:00

JavaScript Date Formats

TypeExample / MethodDescription / Usage
ISO Input"2025-10-08"Standard, cross-browser reliable
ISO Input with Time"2025-10-08T18:30:00"Includes time, local
ISO Input UTC"2025-10-08T18:30:00Z"UTC time, ideal for servers/APIs
Short Date (US)"10/08/2025"Browser-dependent, US-style
Long Date"October 8, 2025"Human-readable, display-friendly
Milliseconds / Timestamp1759927762375Useful for calculations & storage
toString()Wed Oct 08 2025 18:30:00 GMT+0530Default full date & time, local timezone
toDateString()Wed Oct 08 2025Human-readable date only
toTimeString()18:30:00 GMT+0530Time only
toUTCString()Wed, 08 Oct 2025 13:00:00 GMTUTC date & time
toISOString()2025-10-08T13:00:00.000ZISO 8601, UTC
toLocaleString()10/8/2025, 6:30:00 PMLocalized date & time
toLocaleDateString()10/8/2025Localized date only
toLocaleTimeString()6:30:00 PMLocalized time only

 

Article 0 of 0