Guide for – JavaScript Date Methods

JavaScript Get Date Functions- Today we discuss about javascript get date methods. When we want to set or get date value that time we are used javascript date methods. Javascript get date Methods can be expressed in years, months, days, hours, minutes, seconds or milliseconds.

The Javascript get date methods are an inbuilt function in JavaScript which returns the number of milliseconds since

JavaScript Get Date Methods

Contents

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

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

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

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

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

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

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

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

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
Spread the love

Be First to Comment

Leave a Reply

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