1// these are the most useful ones IMO
2var time = new Date();
3time.getDate(); // returns value 1-31 for day of the month
4time.getDay(); //returns value 0-6 for day of the week
5time.getFullYear(); //returns a 4 digit value for the current year
6time.getHours(); //returns value 0-23 for the current hour
7time.getMinutes(); //returns value 0-59 for the current minute of the hour
8time.getSeconds(); //returns value 0-59 for current second of the minute
9time.getMilliseconds(); //returns value 0-999 for current ms of the second
10time.getTime(); //returns date as ms since Jan 1, 1970
11time.toDateString(); //returns a string (e.g. "Fri May 9 2020")
12time.toLocaleString(); //returns date and time (e.g. "9/12/2015, 6:08:25 PM")
13time.toLocaleTimeString(); //returns time (e.g. "6:08:25 PM")
14time.toLocaleDateString(); //returns date (e.g. "9/12/2015")
1var d= new Date();
2d.getFullYear(); //Get the year as a four digit number (yyyy)
3d.getMonth(); //Get the month as a number (0-11)
4d.getDate(); //Get the day as a number (1-31)
5d.getHours(); //Get the hour (0-23)
6d.getMinutes(); //Get the minute (0-59)
7d.getSeconds(); //Get the second (0-59)
8d.getMilliseconds() //Get the millisecond (0-999)
9d.getTime(); //Get the time (milliseconds since January 1, 1970)
10d.getDay(); //Get the weekday as a number (0-6)
11d.Date.now(); //Get the time. ECMAScript 5.
12d.setDate() //Set the day as a number (1-31)
13d.setFullYear() //Set the year (optionally month and day)
14d.setHours() //Set the hour (0-23)
15d.setMilliseconds() //Set the milliseconds (0-999)
16d.setMinutes() //Set the minutes (0-59)
17d.setMonth() //Set the month (0-11)
18d.setSeconds() //Set the seconds (0-59)
19d.setTime() //Set the time (milliseconds since January 1, 1970)
1// Several ways to create a Date object
2let today = new Date();
3let birthday = new Date("December 17, 1995 03:24:00");
4let birthday = new Date("1995-12-17T03:24:00");
5let birthday = new Date(1995, 11, 17); // the month is 0-indexed
6let birthday = new Date(1995, 11, 17, 3, 24, 0);
7let birthday = new Date(628021800000); // passing epoch timestamp
8
9// To get Date, Month and Year or Time
10let [month, date, year] = new Date().toLocaleDateString("en-US").split("/");
11let [hour, minute, second] = new Date()
12 .toLocaleTimeString("en-US")
13 .split(/:| /);
14
15// Two digit years map to 1900 – 1999
16let date = new Date(98, 1); // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT)
17// Deprecated method; 98 maps to 1998 here as well
18date.setYear(98); // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT)
19date.setFullYear(98); // Sat Feb 01 0098 00:00:00 GMT+0000 (BST)
1var d= new Date();
2d.getFullYear();//Get the year as a four digit number (yyyy)
3d.getMonth();//Get the month as a number (0-11)
4d.getDate();//Get the day as a number (1-31)
5d.getHours();//Get the hour (0-23)
6d.getMinutes();//Get the minute (0-59)
7d.getSeconds();//Get the second (0-59)
8d.getMilliseconds();//Get the millisecond (0-999)
9d.getTime();//Get the time (milliseconds since January 1, 1970)
1const d = new Date();
2
3d.getMonth() + 1; // Month [mm] (1 - 12)
4d.getDate(); // Day [dd] (1 - 31)
5d.getFullYear(); // Year [yyyy]
1Pulling Date and Time Values
2getDate()
3Get the day of the month as a number (1-31)
4getDay()
5The weekday as a number (0-6)
6getFullYear()
7Year as a four digit number (yyyy)
8getHours()
9Get the hour (0-23)
10getMilliseconds()
11The millisecond (0-999)
12getMinutes()
13Get the minute (0-59)
14getMonth()
15Month as a number (0-11)
16getSeconds()
17Get the second (0-59)
18getTime()
19Get the milliseconds since January 1, 1970
20getUTCDate()
21The day (date) of the month in the specified date according to universal time (also available for
22day, month, fullyear, hours, minutes etc.)
23parse
24Parses a string representation of a date, and returns the number of milliseconds since January