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)
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 handleTime = (dataD) => {
2 let data= new Date(dataD)
3 let hrs = data.getHours()
4 let mins = data.getMinutes()
5 if(hrs<=9)
6 hrs = '0' + hrs
7 if(mins<10)
8 mins = '0' + mins
9 const postTime= hrs + ':' + mins
10 return postTime
11 }
1new Date();
2// Sat Jan 16 2021 22:08:57 GMT-0500 (Eastern Standard Time)
3Date.now();
4// 1610852869057 -> Seconds passed since Jan 1,1970
5
6// Set the date
7new Date(year, month, day hours, minutes, seconds, milliseconds)