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 today = new Date();
2var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
3
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 }
1var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
2
3// formats below assume the local time zone of the locale;
4// America/Los_Angeles for the US
5
6// US English uses 12-hour time with AM/PM
7console.log(date.toLocaleTimeString('en-US'));
8// "7:00:00 PM"
9
10// British English uses 24-hour time without AM/PM
11console.log(date.toLocaleTimeString('en-GB'));
12// "03:00:00"
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")
1let today = new Date();
2let time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();