Date
Date Constructor
Zero parameter
const date1 = new Date();
Timestamp Number
- An integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC
const date2 = new Date(0);
String
const date3 = new Date("16 Jan 2022");
// ISO formats
const date4 = new Date("2022-12-16");
const date5 = new Date("2022-12-16T11:25:30");
const date6 = new Date("2022-12-16T11:25:30Z");
const date7 = new Date("2022-12-16T11:25:30+05:30");
Individual components year, month, date, hours, mins, secs, ms
- Integer value representing the month, beginning with
0
for January to 11
for December.
const date8 = new Date(2022, 11, 15);
Methods
Static Methods
Date.now();
Date.parse();
Instance Methods
Get methods
getFullYear
- Preferred
getMonth
getDate
- Returns the date of the month (0-11)
getDay
- Return the day of the weak (0-6) [0 - Sunday, 1-Monday]
getHours
getMinutes
getSeconds
getMilliSeconds
Set Methods
setFullYear
- Preferred
setMonth
setDate
setDay
setHours
setMinutes
setSeconds
setMilliSeconds
Display Methods
toString
- Fri Dec 16 2022 12:39:40 GMT+0530 (India Standard Time)
toDateString
toTimeString
toLocaleString
- 16/12/2022, 12:39:40 pm
toLocaleDateString
toLocaleTimeString
toUTCString
- Fri, 16 Dec 2022 07:09:40 GMT
toISOString
- 2022-12-16T07:09:40.469Z
toJSON
- 2022-12-16T07:09:40.469