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.
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.
| Method | What 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. |
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. |
Choose the output method according to whether you need a machine-friendly string, a localised display, only the date, or only the time.
toString() for a general local date-time string.toLocaleString() for locale-aware date and time output.toDateString() for the date portion.toLocaleDateString() for locale-aware date-only output.toTimeString() for the time portion.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());
setTimeout() schedules a callback after a delay.clearTimeout() cancels a pending timeout.Date and time projects combine the methods above into practical examples such as date differences, calendar calculations and time-based interfaces.
getDate() means day of the month; getDay() means weekday.2026-09-10 is interpreted differently from a local date-time string without an offset; include an explicit offset when the instant matters.10/09/2026 when portability matters.Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| 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 ?? | |