JavaScript | Get Date Methods
There are various methods to get the date in JavaScript. The data values can get like years, months, days, hours, minutes, seconds, milliseconds from a Date Object.
Method:
- getDate(): It is used to get the day as a number (1-31).
- getFullYear(): It is used to get the year.
- getHours(): It is used to get the hour (0-23).
- getMilliseconds(): It is used to get the milliseconds (0-999).
- getMinutes(): It is used to get the minutes (0-59).
- getMonth(): It is used to get the month (0-11).
- getSeconds(): It is used to get the seconds (0-59).
- getTime(): It is used to get the time.
- getDay(): It is used to get the weekday as a number (0-6).
- Date.now(): It is used to get the time.
- The getHours() Method: The getHours() method in JavaScript is used to return the hours of a date as a number (0-23).
Example:
<!DOCTYPE html><html><head><title>JavaScript getHours() Method</title></head><bodystyle="text-align:center;"><h1>GeeksForGeeks</h1><h2>JavaScript getHours()</h2><pid="GFG"></p><!-- Script to use getHours() method --><script>var d = new Date();document.getElementById("GFG").innerHTML= d.getHours();</script></body></html>Output:

- The getDate() Method: The getDate() method in JavaScript is used to return the day of a date as a number (1-31).
Example:
<!DOCTYPE html><html><head><title>JavaScript getDate() Method</title></head><bodystyle="text-align:center;"><h1>GeeksForGeeks</h1><h2>JavaScript getDate()</h2><pid="GFG"></p><!-- Script to use getDate() method --><script>var d = new Date();document.getElementById("GFG").innerHTML= d.getDate();</script></body></html>Output:

- The getMonth() Method: The getMonth() method in JavaScript is used to return the month of a date as a number (0-11).
Example:
<!DOCTYPE html><html><head><title>JavaScript getMonth() Method</title></head><bodystyle="text-align:center;"><h1>GeeksForGeeks</h1><h2>JavaScript getMonth()</h2><pid="GFG"></p><!-- Script to use getMonth() method --><script>var d = new Date();document.getElementById("GFG").innerHTML= d.getMonth();</script></body></html>Output:

- The getFullYear() Method: The getFullYear() method in JavaScript is used to return the number of milliseconds.
Example:
<!DOCTYPE html><html><head><title>JavaScript getFullYear() Method</title></head><bodystyle="text-align:center;"><h1>GeeksForGeeks</h1><h2>JavaScript getFullYear()</h2><pid="GFG"></p><!-- Script to use getFullYear() method --><script>var d = new Date();document.getElementById("GFG").innerHTML= d.getFullYear();</script></body></html>Output:

- The getTime() Method: The getTime() method in JavaScript is used to return the number of milliseconds.
Example:
<!DOCTYPE html><html><head><title>JavaScript getTime() Method</title></head><bodystyle="text-align:center;"><h1>GeeksForGeeks</h1><h2>JavaScript getTime()</h2><pid="GFG"></p><!-- Script to use getTime() method --><script>var d = new Date();document.getElementById("GFG").innerHTML= d.getTime();</script></body></html>Output:

- The getSeconds() Method: The getSeconds() method in JavaScript returns the seconds of a date object (0-59).
Example:
<!DOCTYPE html><html><head><title>JavaScript getSeconds() Method</title></head><bodystyle="text-align:center;"><h1>GeeksForGeeks</h1><h2>JavaScript getSeconds()</h2><pid="GFG"></p><!-- Script to use getSeconds() method --><script>var d = new Date();document.getElementById("GFG").innerHTML= d.getSeconds();</script></body></html>Output:



