JavaScript Date Object and Date Methods

JavaScript's Date object represents a single point in time as a numeric timestamp. You create a date with new Date(), then use getter, setter, formatting, UTC, and timer-related methods depending on what you need to do.

Basic syntax:

const now = new Date();
console.log(now);

A Date stores an instant internally. Methods such as getHours() and getDate() read that instant in the user's local time zone; methods beginning with getUTC read the same instant as UTC.

Creating JavaScript Date Objects Top ↑

The most common constructor forms are shown below. Month numbers in the numeric constructor are zero-based: January is 0 and December is 11.

const now = new Date();
const fromTimestamp = new Date(0);
const localDate = new Date(2026, 8, 10, 14, 30);
const isoDate = new Date("2026-09-10T14:30:00+05:30");

For a fuller explanation of constructor forms, timestamps, validation, and date-string parsing, see JavaScript Date object.

Reading Date and Time Values Top ↑

MethodWhat it returns
getTime()Milliseconds since 1 January 1970 00:00:00 UTC.
getMonth()Local month from 0 to 11.
getFullYear()Local full year, such as 2026.
getDate()Local day of the month from 1 to 31.
getDay()Local weekday from 0 (Sunday) to 6 (Saturday).
getHours()Local hour from 0 to 23.
getMinutes()Local minutes from 0 to 59.
getSeconds()Local seconds from 0 to 59.

Changing Date and Time Values Top ↑

Date setter methods mutate the existing Date object. JavaScript normalizes values outside their usual range, which can be useful for date arithmetic but can also hide mistakes.

setDate()Set the day of the month.
setMonth()Set the zero-based month.
setFullYear()Set the full year.
setHours()Set local hours.
setMinutes()Set local minutes.

Formatting a JavaScript Date Top ↑

Choose the output method according to whether you need a machine-friendly string, a localised display, only the date, or only the time.

UTC and Time Zones Top ↑

Use the UTC Date methods when you need to read or create values in Coordinated Universal Time. For named time zones, Intl.DateTimeFormat or the timeZone option of locale-formatting methods is generally clearer than manually adding offsets.

const now = new Date();
console.log(now.getHours());
console.log(now.getUTCHours());
console.log(now.getTimezoneOffset());

Timers, Countdowns and Clocks Top ↑

JavaScript Date Projects Top ↑

Date and time projects combine the methods above into practical examples such as date differences, calendar calculations and time-based interfaces.

Analog clock drawn with HTML canvas and JavaScript

Video: real-time JavaScript clock

Important JavaScript Date Pitfalls Top ↑

  • Numeric months are zero-based.
  • getDate() means day of the month; getDay() means weekday.
  • Local getters depend on the host time zone.
  • A date-only ISO string such as 2026-09-10 is interpreted differently from a local date-time string without an offset; include an explicit offset when the instant matters.
  • Do not parse ambiguous strings such as 10/09/2026 when portability matters.
  • Check invalid user input before using the resulting date.

All Date Projects




Subscribe to our YouTube Channel here



plus2net.com







Vijay

21-02-2012

how to alert a user after he reached the duedate for payment of water bill(for example)lets say 2 months ??



✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer