JavaScript Get Date Method with Examples

Get-Date Functions/Methods in js. Here, we would like to share with you, javascript get date methods with their examples.

The Javascript get date methods are an inbuilt function in JavaScript which returns the years, months, days, hours, minutes, seconds, milliseconds from a Date Object.

You can use the javascript get methods for e.g. get current date and time in javascript, display current date and time in html using javascript get date methods.

JavaScript Get Date Methods

The javascript get date methods are given below:

  • getFullYear()
  • getMonth()
  • getDate()
  • getHours()
  • getMinutes()
  • getSeconds()
  • getMilliseconds()
  • getDay()

1: The getFullYear() method

The method gives four digit number of the current year according to local time.

Example

var date = new Date();
document.write('date = ' + date.getFullYear() +"<br>");
Output
// return current year
2019

2: The getMonth() Method

The date.getMonth() is an inbuilt function of javascript. The getMonth() method returns the month of a date as a number (0-11).

Example

var date = new Date();
document.write('month = ' + date.getMonth() +"<br>");
it is return current month
return //
2

3: The getDate() Method

The JavaScript getDate() method returns the day of the month for the specified date according to local time. The getDate() method is return no an integer between 1 and 31.

Example

var date = new Date();
document.write('date = ' + date.getDate() +"<br>");
Output
//Return current date
18

4: The getHours() Method

The JavaScript getHours() method returns the hours of the day for the specified date according to local time. The getDate() method is return no an integer between 0 and 23.

Example

var date = new Date();
document.write('Hours = ' + date.getHours() +"<br>");
Output
return hours of day
22

5: The getMinutes() Method

The JavaScript getMinutes() method returns the minutes of the hour for the specified date using local time. The getDate() method is return no an integer between 0 and 59.

var date = new Date();
document.write('Minutes = ' + date.getMinutes() +"<br>");
output
return minutes of the hour
25

6: The getSeconds() Method

The JavaScript getSeconds() method returns the seconds of a date using a local time and return num 0 to 59 in seconds.

var date = new Date();
document.write('Seconds = ' + date.getSeconds() +"<br>");
output
return second of the minute
35

7: The getMilliseconds() Method

The JavaScript getMilliseconds() method returns the milliseconds of a date using a local time and return num 0 to 59 in milliseconds.

Example

var date = new Date();
document.write('MilliSeconds = ' + date.getMilliseconds() +"<br>");
Output
return millisecond
55

8: The getDay() Method

The JavaScript getDay() method returns the weekday of a date using a local time and return num 0 to 6.

var date = new Date();
document.write('Day = ' + date.getDay() +"<br>");
output
return
1

Note :- You can create digital clock in javascript using the javascript get methods. See the following post:- javaScript Digital Clock with date.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *