codemaniacstudio

Write a note on Date object in javascript. Explain any 5 date methods with example.

Write a note on Date object in javascript. Explain any 5 date methods with example.

SOLUTION....

JavaScript Date object — short note

The JavaScript Date object represents a specific moment in time (internally as milliseconds since the Unix epoch: 1 Jan 1970 UTC). It provides methods to create, read and modify date/time values and to convert between formats. You can create dates in several ways:

Five common Date methods (with examples)

1. getFullYear()

Returns the 4-digit year of the date.

2. getMonth()

Returns month index (0–11). Remember: January = 0, December = 11.

3. getDate()

Returns the day of the month (1–31).

4. getDay()

Returns the day of week (0–6). In JavaScript 0 = Sunday, 1 = Monday, … 6 = Saturday.

5. getTime()

Returns the numeric value — milliseconds since 1 Jan 1970 UTC. Useful for comparisons, sorting, or arithmetic.

Exit mobile version