Date in JavaScript

In this tutorial, we will learn Date in JavaScript. JavaScript Date method helps us to do various basic functions like to get the current date, time and year. We can also add timers on the Web pages with the help of the date object. Date object provides us with four types of constructors we can use any according to our requirement to create an object of Date. It also has a lot of methods which we will read in this tutorial.

Firstly we will check constructors which are available to us to create an object of Date.

  • Date()
  • Date(milliseconds)
  • Date(dateString)
  • Date(year, month, day, hours, minutes, seconds, milliseconds)

Methods of Date: 

There is great collection of methods available in Date Object. Check the following table.

Method Description
getDate() This method would return current according to local time.
getDay() It returns the integer value between 0 and 6 that represents the day of the week on the basis of local time.
getFullYears() It returns the integer value that represents the year on the basis of local time.
getHours() It returns the integer value between 0 and 23 that represents the hours on the basis of local time.
getMilliseconds() It returns the integer value between 0 and 999 that represents the milliseconds on the basis of local time.
getMinutes() It returns the integer value between 0 and 59 that represents the minutes on the basis of local time.
getMonth() It returns the integer value between 0 and 11 that represents the month on the basis of local time.
getSeconds() It returns the integer value between 0 and 60 that represents the seconds on the basis of local time.
setDate() It sets the day value for the specified date on the basis of local time.
setDay() It sets the particular day of the week on the basis of local time.
setFullYears() It sets the year value for the specified date on the basis of local time.
setHours() It sets the hour value for the specified date on the basis of local time.
setMilliseconds() It sets the millisecond value for the specified date on the basis of local time.
setMinutes() It sets the minute value for the specified date on the basis of local time.
setMonth() It sets the month value for the specified date on the basis of local time.
setSeconds() It sets the second value for the specified date on the basis of local time.
Spread the love
Scroll to Top
×