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>chevron_rightfilter_noneOutput:

- 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>chevron_rightfilter_noneOutput:

- 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>chevron_rightfilter_noneOutput:

- 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>chevron_rightfilter_noneOutput:

- 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>chevron_rightfilter_noneOutput:

-
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>chevron_rightfilter_noneOutput:

Recommended Posts:
- JavaScript | Set Date Methods
- JavaScript | Date
- JavaScript | Date.now()
- Date.UTC( ) In JavaScript
- JavaScript | Object Methods
- JavaScript | date.toLocaleTimeString()
- How to convert a JavaScript date to UTC?
- JavaScript | date.toLocaleString()
- JavaScript | date.toLocaleDateString()
- How to get the current date in JavaScript ?
- JavaScript | Date.parse()
- JavaScript | date.setUTCMonth()
- JavaScript | Date Formats
- Increment a given date in JavaScript
- JavaScript | Date Objects
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



