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
1var today = new Date();
2var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
3var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
4var dateTime = date+' '+time;
5
1// The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
2
3
4var start = new Date().getTime();
5
6for (i = 0; i < 50000; ++i) {
7// do something
8}
9
10var end = new Date().getTime();
11var time = end - start;
12alert('Execution time: ' + time);
1var today = new Date();
2var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
3
1var d = new Date();
2var n = d.toLocaleTimeString();
3document.getElementById("timer").innnerHTML = n;