- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript - Get Date Methods
Following are the date methods −
Method | Description |
---|---|
getFullYear() | Returns the year as a four digit number. |
getMonth() | Returns the month as a number. |
getDate() | Returns the day as a number. |
getHours() | Return the hour. |
getMinutes() | Returns the minutes. |
getSeconds() | Returns the seconds. |
getMilliseconds() | Returns the millisecond. |
getTime() | Returns the time in milliseconds since January 1,1970. |
getDay() | Returns the weekday as a number. |
Date.now() | Returns the number of milliseconds since January 1,1970 00:00:00 UTC. |
Following is the code implementing some of the date methods in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } </style> </head> <body> <h1>JavaScript Date Methods</h1> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above buttons to get some date Methods </h3> <script> let sampleEle = document.querySelector(".sample"); let date = new Date(); document.querySelector(".Btn").addEventListener("click", () => { sampleEle.innerHTML += "getFullYear() = " + date.getFullYear() + "<br>"; sampleEle.innerHTML += "getMinutes() = " + date.getMinutes() + "<br>"; sampleEle.innerHTML += "Date.now() = " + Date.now() + "<br>"; sampleEle.innerHTML += "getMonth() = " + date.getMonth() + "<br>"; }); </script> </body> </html>
Output
On clicking the ‘CLICK HERE’ button −
- Related Articles
- JavaScript Set Date Methods
- Get all methods of any object JavaScript
- How to get yesterday’s date in JavaScript?
- Get current date/time in seconds - JavaScript?
- How do I get the current date in JavaScript?
- How to get current date and time using JavaScript?
- How to get current date and time in JavaScript?
- How to get current date/time in seconds in JavaScript?
- How do I get the current date and time in JavaScript?
- How can I get time and date since epoch in JavaScript?
- Get the correct century from 2-digit year date value - JavaScript?
- JavaScript Object Methods
- Using GET Methods in Perl
- Share methods in JavaScript
- JavaScript Basic Array Methods

Advertisements