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")
1setTimeout(function(){
2 //code goes here
3}, 2000); //Time before execution
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<html>
2 <head>
3 <title>JavaScript setHours Method</title>
4 </head>
5 <body>
6 <script>
7 var dt = new Date();
8 dt.setHours( dt.getHours() + 2 );
9 document.write( dt );
10 </script>
11 </body>
12</html>
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)
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