HeoLab
ToolsBlogAboutContact
HeoLab

Free developer tools with AI enhancement. Built for developers who ship.

Tools

  • JSON Formatter
  • JWT Decoder
  • Base64 Encoder
  • Timestamp Converter
  • Regex Tester
  • All Tools →

Resources

  • Blog
  • What is JSON?
  • JWT Deep Dive
  • Base64 Explained

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 HeoLab. All rights reserved.

Tools work in your browser. Zero data retention.

HomeBlogJavaScript Date API Cheatsheet for Developers
Table of Contents▾
  • Table of Contents
  • Creating Dates
  • Getting Components
  • Formatting
  • Date Arithmetic
  • Comparisons
tutorials#timestamp#javascript#datetime

JavaScript Date API Cheatsheet for Developers

A concise reference for every Date operation you'll need — parsing, formatting, arithmetic, comparison, and timezone handling.

Trong Ngo
February 22, 2026
2 min read

Table of Contents

  • Creating Dates
  • Getting Components
  • Formatting
  • Date Arithmetic
  • Comparisons

Creating Dates

new Date()                          // Now
new Date("2025-02-22T14:30:00Z")    // From ISO string (UTC)
new Date(1708560000 * 1000)         // From Unix timestamp
new Date(2025, 1, 22)               // Feb 22, 2025 LOCAL time (month is 0-indexed)

Getting Components

const d = new Date("2025-02-22T14:30:45.123Z");

d.getUTCFullYear()  // 2025
d.getUTCMonth()     // 1 (0-indexed! January=0)
d.getUTCDate()      // 22
d.getUTCHours()     // 14
d.getTime()         // 1708560000000 (ms since epoch)

Formatting

const d = new Date("2025-02-22T14:30:00Z");

d.toISOString()                   // "2025-02-22T14:30:00.000Z"
d.toLocaleDateString("en-US")     // "2/22/2025"
d.toLocaleDateString("de-DE")     // "22.2.2025"

// Custom format with Intl
new Intl.DateTimeFormat("en-US", {
  year: "numeric", month: "long", day: "numeric"
}).format(d); // 'February 22, 2025'

Date Arithmetic

const d = new Date("2025-02-22T00:00:00Z");
const ms = d.getTime();

// Add 7 days
new Date(ms + 7 * 24 * 60 * 60 * 1000);

// Difference in days
const diff = (dateA - dateB) / (1000 * 60 * 60 * 24);

Comparisons

const a = new Date("2025-01-01");
const b = new Date("2025-06-01");

a < b   // true
a - b   // negative (ms difference)

// Sort array of dates
dates.sort((a, b) => new Date(a.date) - new Date(b.date));

Try These Tools

Unix Timestamp Converter

Convert Unix timestamps to human-readable dates and vice versa. Supports all major timezone formats.

Related Articles

Using Regex for Form Validation: Patterns and Pitfalls

2 min read

Date and Time Best Practices for APIs

1 min read

ISO 8601 Date Format: The Standard Every Developer Should Know

1 min read

Back to Blog

Table of Contents

  • Table of Contents
  • Creating Dates
  • Getting Components
  • Formatting
  • Date Arithmetic
  • Comparisons

Related Articles

Using Regex for Form Validation: Patterns and Pitfalls

2 min read

Date and Time Best Practices for APIs

1 min read

ISO 8601 Date Format: The Standard Every Developer Should Know

1 min read