JavaScript Date

Beginner
⏱️ 16 min read
📚 Updated: Jul 2026
🎯 46 Tutorials
Date object

What You’ll Learn

Dates and times appear in almost every app — logs, bookings, countdowns, and APIs. This hub links to 46 Date method tutorials for reading parts, mutating values, formatting strings, and working in UTC.

01

new Date

Create dates

02

get*

Read parts

03

set*

Change parts

04

UTC

Global time

05

Format

toISOString

06

46 guides

Full index

Introduction

JavaScript provides a built-in Date object for working with moments in time. Unlike many languages, months are zero-based (0 = January), and the object is mutable — setters change the same instance.

What Are Date Methods?

Date methods fall into a few groups: getters read year, month, day, and clock fields; setters update them; formatters produce strings; and static helpers like Date.now() and Date.parse() work without an instance.

💡
Beginner Tip

Store and exchange times as UTC timestamps or ISO strings (toISOString()). Convert to local display only at the UI layer with toLocaleString().

Local Time vs UTC

  • LocalgetHours(), setMonth() use the user’s timezone.
  • UTCgetUTCHours(), setUTCDate() ignore local offset.
  • TimestampgetTime() and Date.now() return milliseconds since the epoch (timezone-agnostic).

📝 Syntax

Create and inspect a date:

JavaScript
const now = new Date();
const timestamp = Date.now();

console.log(now.getFullYear());   // local year
console.log(now.getUTCMonth());   // UTC month (0–11)
console.log(now.toISOString());   // "2026-07-17T10:30:00.000Z"

Method groups

GroupExamplesPurpose
StaticDate.now(), Date.parse()Timestamps without an instance
GettersgetDate(), getMonth()Read components
SetterssetHours(), setFullYear()Mutate the Date
FormattoISOString(), toLocaleDateString()Human or API strings

⚡ Quick Reference

GoalMethod
Current timestampDate.now()
Day of monthdate.getDate() (1–31)
Month (remember 0-based)date.getMonth()
API string (UTC)date.toISOString()
Locale displaydate.toLocaleDateString()
Add daysdate.setDate(date.getDate() + n)

When to Use Which Methods

  • NowDate.now() for performance timing or unique IDs.
  • Parse user inputnew Date(string) or Date.parse() (validate results — parsing is inconsistent for some formats).
  • DisplaytoLocaleDateString() / toLocaleTimeString() for UI.
  • APIs & databasestoISOString() for JSON payloads.
  • Math across days — convert to timestamps with getTime(), add milliseconds, create new Date(ms).

👀 Sample Date Output

Different methods format the same moment differently:

toDateString() → Fri Jul 17 2026 toISOString() → 2026-07-17T10:30:00.000Z toLocaleString() → 7/17/2026, 4:00:00 PM (locale-dependent)

Date Method Tutorial Index

Search by method name or browse by category. Each tutorial includes syntax, five try-it examples, and FAQs.

Getting Started

4 tutorials

Create timestamps and read core Date concepts first.

MethodDescriptionTutorial
Date.now()Returns the current timestamp in milliseconds since the Unix epoch.Open
Date.parse()Parses a date string and returns milliseconds since 1 Jan 1970 UTC, or NaN if invalid.Open
Date.UTC()Builds a UTC timestamp from year, month, day, and optional time parts.Open
getTime()Returns milliseconds since 1 Jan 1970 UTC — the internal timestamp.Open

Local Getters

9 tutorials

Read date and time parts in the user's local timezone.

MethodDescriptionTutorial
getDate()Returns the day of the month (1–31) in local time.Open
getDay()Returns the day of the week (0 = Sunday … 6 = Saturday) in local time.Open
getFullYear()Returns the four-digit year in local time.Open
getMonth()Returns the month index (0 = January … 11 = December) in local time.Open
getHours()Returns the hour (0–23) in local time.Open
getMinutes()Returns the minutes (0–59) in local time.Open
getSeconds()Returns the seconds (0–59) in local time.Open
getMilliseconds()Returns the milliseconds portion (0–999) in local time.Open
getTimezoneOffset()Returns local offset from UTC in minutes (positive west of UTC).Open

UTC Getters

8 tutorials

Read components in Coordinated Universal Time.

MethodDescriptionTutorial
getUTCDate()Returns the day of the month (1–31) in UTC.Open
getUTCDay()Returns the day of the week (0–6) in UTC.Open
getUTCFullYear()Returns the four-digit year in UTC.Open
getUTCMonth()Returns the month index (0–11) in UTC.Open
getUTCHours()Returns the hour (0–23) in UTC.Open
getUTCMinutes()Returns minutes (0–59) in UTC.Open
getUTCSeconds()Returns seconds (0–59) in UTC.Open
getUTCMilliseconds()Returns milliseconds (0–999) in UTC.Open

Local Setters

8 tutorials

Change date and time parts in local time (mutates the object).

MethodDescriptionTutorial
setDate()Sets the day of the month in local time; mutates the Date object.Open
setFullYear()Sets the year (and optionally month and date) in local time.Open
setMonth()Sets the month index in local time; may roll the day if needed.Open
setHours()Sets the hour and optionally minutes, seconds, and ms in local time.Open
setMinutes()Sets minutes and optionally seconds and ms in local time.Open
setSeconds()Sets seconds and optionally milliseconds in local time.Open
setMilliseconds()Sets the milliseconds component in local time.Open
setTime()Sets the date from a millisecond timestamp since the epoch.Open

UTC Setters

7 tutorials

Change components in UTC.

MethodDescriptionTutorial
setUTCDate()Sets the day of the month in UTC.Open
setUTCFullYear()Sets the year in UTC, optionally with month and date.Open
setUTCMonth()Sets the month index in UTC.Open
setUTCHours()Sets the hour in UTC, optionally with minutes, seconds, and ms.Open
setUTCMinutes()Sets minutes in UTC, optionally seconds and ms.Open
setUTCSeconds()Sets seconds in UTC, optionally milliseconds.Open
setUTCMilliseconds()Sets the milliseconds component in UTC.Open

Formatting & Conversion

10 tutorials

Turn Date objects into strings for display or APIs.

MethodDescriptionTutorial
toISOString()Returns an ISO 8601 UTC string — ideal for APIs and JSON.Open
toLocaleString()Formats date and time using locale-specific rules.Open
toLocaleDateString()Formats the date portion using locale-specific rules.Open
toLocaleTimeString()Formats the time portion using locale-specific rules.Open
toDateString()Returns a human-readable date string (weekday, month, day, year).Open
toTimeString()Returns a human-readable time string with timezone info.Open
toUTCString()Returns a UTC date/time string in HTTP-style format.Open
toString()Returns a default string representation of the date and time.Open
toJSON()Returns an ISO string; used when JSON.stringify serializes a Date.Open
valueOf()Returns the primitive millisecond timestamp (same as getTime()).Open

Examples Gallery

Open DevTools Console (F12) and paste each snippet to see formatted date output.

📚 Create & Read

Timestamps and date components.

Example 1 — Current Time with Date.now()

Get milliseconds since the Unix epoch without creating a Date object.

JavaScript
const ms = Date.now();
const date = new Date(ms);

console.log("Timestamp:", ms);
console.log("ISO:", date.toISOString());

How It Works

Date.now() is the fastest way to capture “right now” for comparisons and storage. Wrap in new Date(ms) when you need getters or formatters.

Example 2 — Read Date Parts

Extract year, month, and day — remember months are zero-based.

JavaScript
const d = new Date(2026, 6, 17); // Jul 17, 2026 (month 6)

console.log("Year:", d.getFullYear());
console.log("Month index:", d.getMonth());   // 6 = July
console.log("Day:", d.getDate());

How It Works

The Date constructor accepts (year, monthIndex, day, …) in local time. Display month as getMonth() + 1 for users.

📈 Format & Manipulate

Strings for users and APIs.

Example 3 — Format with toDateString() and toISOString()

Human-readable local date vs standard UTC for APIs.

JavaScript
const currentDate = new Date();

console.log("Date:", currentDate.toDateString());
console.log("ISO:", currentDate.toISOString());

How It Works

toDateString() is readable but not machine-sortable. Prefer toISOString() when sending dates to a server or database.

Example 4 — Locale Formatting

Present time and weekday in the user’s locale.

JavaScript
const currentDate = new Date();

console.log("Time:", currentDate.toLocaleTimeString());
console.log(
  "Weekday:",
  currentDate.toLocaleDateString("en-US", { weekday: "long" })
);

How It Works

Locale methods respect the user’s language and regional settings. Pass options for fine control over weekday, date, and time parts.

Example 5 — Add Days with setDate()

Roll the calendar forward without manual month math.

JavaScript
const deadline = new Date(2026, 6, 28);
deadline.setDate(deadline.getDate() + 7);

console.log("One week later:", deadline.toDateString());

How It Works

setDate() normalizes overflow — adding 7 to July 28 lands in August automatically. For complex calendar rules, consider libraries like Temporal (future) or date-fns.

💬 Usage Tips

  • Timezone awareness — document whether UI shows local or UTC; use UTC getters for server sync.
  • Validate parsed datesisNaN(date.getTime()) detects invalid Date objects.
  • Prefer ISO in JSONJSON.stringify calls toJSON() → ISO string.
  • Avoid string parsing trapsnew Date("2026-07-17") may parse as UTC midnight; test your format.
  • Search this index — jump to any of 46 method pages above.

⚠️ Common Pitfalls

  • Zero-based months — July is 6, not 7, in getters and the constructor.
  • Mutable dates — setters change the original object; clone first if needed.
  • Daylight saving jumps — local setHours() can skip or repeat hours on DST boundaries.
  • Legacy Date.parse — implementation-dependent for non-ISO strings; prefer explicit parsing.
  • Sort as strings — compare getTime() numbers, not formatted date strings.

🧠 How Date Methods Work

1

Internal timestamp

Every Date stores milliseconds since 1 Jan 1970 00:00:00 UTC.

Epoch
2

Getters / setters

Methods project that instant into local or UTC calendar fields.

Project
3

Formatters

toISOString and locale methods produce strings for display or transport.

Format
=

Time-aware apps

Schedules, logs, and deadlines become manageable with the right method for each job.

Browser Support

The Date object and its methods are part of core JavaScript — supported in every browser and Node.js version. Locale formatting depends on the host’s Intl implementation; ISO methods behave consistently everywhere.

Baseline · ES1+

Date.prototype methods

Supported in Chrome, Firefox, Safari, Edge, IE 3+, and all modern Node.js versions. Static helpers like Date.now() are universally available in current runtimes.

100% Core API
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
Date methods Universal

Bottom line: Production-safe across all modern and legacy environments. Prefer toISOString() for APIs and toLocaleString() for user-facing display.

🎉 Conclusion

JavaScript Date methods give you full control over reading, changing, and formatting moments in time. Start with Date.now(), getters, and toISOString(), then explore UTC and locale APIs as needed.

Use the searchable index to open all 46 tutorials — each includes try-it labs and FAQs.

💡 Best Practices

✅ Do

  • Store UTC timestamps or ISO strings
  • Use toLocaleString for display
  • Validate with isNaN(date.getTime())
  • Clone before mutating shared dates
  • Compare with getTime() numbers

❌ Don’t

  • Forget months are 0-based
  • Parse ambiguous date strings blindly
  • Assume local getters equal UTC values
  • Sort formatted date strings lexically
  • Memorize all 46 names at once

Key Takeaways

Knowledge Unlocked

Five things to remember about Date methods

Your gateway to 46 method tutorials.

5
Core concepts
0 02

Month 0

Jan = 0

Pitfall
UTC 03

getUTC*

Global time

Sync
ISO 04

toISOString

API format

JSON
46 05

Index

Search all

Ref

❓ Frequently Asked Questions

Date represents a single moment in time internally as milliseconds since the Unix epoch (1 Jan 1970 UTC). You create one with new Date(), Date.now(), or Date.parse(), then use getters and setters to read or change components.
getHours() and setHours() use the user's local timezone. getUTCHours() and setUTCHours() use Coordinated Universal Time. Use UTC methods when storing or comparing times across timezones.
JavaScript Date months are zero-based: 0 = January through 11 = December. Always add 1 when displaying to users unless you format with toLocaleDateString.
Use date.toISOString() for a standard UTC string like 2026-07-17T10:30:00.000Z. For user-facing text, prefer toLocaleDateString() or toLocaleString() with a locale and options.
Yes. setDate(), setHours(), and other setters change the same Date instance in place and return the new timestamp (milliseconds). Clone with new Date(date.getTime()) before mutating if you need the original.
Read the overview, try the five examples, then open getDate() or Date.now() from Getting Started. Use the search box to find any of the 46 method tutorials.
Did you know?

valueOf() and getTime() both return the millisecond timestamp, so comparing dates with > works because JavaScript calls valueOf() when coercing Dates to numbers.

Start with getDate()

Learn how to read the day of the month and build your first date display.

getDate() 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.

10 people found this page helpful