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)
1getDate() in javascript only returns the day as number (1-31)
2
3Example
4var d = new Date();
5document.getElementById("demo").innerHTML = d.getDate();
6
7Output:
822
9
10Method Description
11getFullYear() Get the year as a four digit number (yyyy)
12getMonth() Get the month as a number (0-11)
13getDate() Get the day as a number (1-31)
14getHours() Get the hour (0-23)
15getMinutes() Get the minute (0-59)
16getSeconds() Get the second (0-59)
17getMilliseconds() Get the millisecond (0-999)
18getTime() Get the time (milliseconds since January 1, 1970)
19getDay() Get the weekday as a number (0-6)
20Date.now() Get the time. ECMAScript 5.
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)
1function getTodayDate() {
2 let d = new Date();
3 return d;
4}
5
6console.log(getTodayDate());
7
8//2020-12-06T09:53:14.105Z
1function getDate()
2{
3 let today = new Date();
4 let dd = String(today.getDate()).padStart(2, '0');
5 let mm = String(today.getMonth() + 1).padStart(2, '0'); //janvier = 0
6 let yyyy = today.getFullYear();
7
8 return dd + '/' + mm + '/' + yyyy;
9}