Minifycode 2022-04-25 Viewed 1K times Javascript

In this article, you will learn Date Object in JavaScript. The JavaScript date object can be used to get year, month and day. We can use different Date constructors to create date object. We can display a timer on the webpage by the help of JavaScript date object.

This provide methods to get and set day, month, year, hour, minute and seconds.

<script>var today=new Date();  
  var hrs=today.getHours();  
  var mnts=today.getMinutes();  
  var sec=today.getSeconds();  
  document.getElementById('txt_Date').innerHTML=hrs+":"+mnts+":"+sec;  
</script>

 

toDateString()- Returns the date portion of a Date object.

toISOString()- Returns the date in the form ISO format string.

toJSON()- Returns a string representing the Date object. It also serializes the Date object during JSON serialization.

toString()- Returns the date in the form of string.

toTimeString()- Returns the time portion of a Date object.

toUTCString()- This converts the specified date in the form of string using UTC time zone.

valueOf()- Returns the primitive value of a Date object.

getDate()- Returns the integer value between 1 and 31 that represents the day for the specified date on the basis of local time.

getDay()- Returns the integer value between 0 and 6 that represents the day of the week on the basis of local time.

getFullYears()- Returns the integer value that represents the year on the basis of local time.

getHours()- Returns the integer value between 0 and 23 that represents the hours on the basis of local time.

getMilliseconds()- Returns the integer value between 0 and 999 that represents the milliseconds on the basis of local time.

getMinutes()- Returns the integer value between 0 and 59 that represents the minutes on the basis of local time.

getMonth()- Returns the integer value between 0 and 11 that represents the month on the basis of local time.

getSeconds()- Returns the integer value between 0 and 60 that represents the seconds on the basis of local time.

getUTCDate()- Returns the integer value between 1 and 31 that represents the day for the specified date on the basis of universal time.

getUTCDay()- Returns the integer value between 0 and 6 that represents the day of the week on the basis of universal time.

getUTCFullYears()- Returns the integer value that represents the year on the basis of universal time.

getUTCHours()- Returns the integer value between 0 and 23 that represents the hours on the basis of universal time.

getUTCMinutes()- Returns the integer value between 0 and 59 that represents the minutes on the basis of universal time.

getUTCMonth()- Returns the integer value between 0 and 11 that represents the month on the basis of universal time.

getUTCSeconds()- Returns the integer value between 0 and 60 that represents the seconds on the basis of universal time.

setDate()- Sets the day value for the specified date on the basis of local time.

setDay()- Sets the particular day of the week on the basis of local time.

setFullYears()- Sets the year value for the specified date on the basis of local time.

setHours()- Sets the hour value for the specified date on the basis of local time.

setMilliseconds()- Sets the millisecond value for the specified date on the basis of local time.

setMinutes()- Sets the minute value for the specified date on the basis of local time.

setMonth()- Sets the month value for the specified date on the basis of local time.

setSeconds()- Sets the second value for the specified date on the basis of local time.

setUTCDate()- Sets the day value for the specified date on the basis of universal time.

setUTCDay()- Sets the particular day of the week on the basis of universal time.

setUTCFullYears()- Sets the year value for the specified date on the basis of universal time.

setUTCHours()- Sets the hour value for the specified date on the basis of universal time.

setUTCMilliseconds()- Sets the millisecond value for the specified date on the basis of universal time.

setUTCMinutes()- Sets the minute value for the specified date on the basis of universal time.

setUTCMonth()- Sets the month value for the specified date on the basis of universal time.

setUTCSeconds()- Sets the second value for the specified date on the basis of universal time.

 

Date Object in JavaScript, The JavaScript date object can be used to get year, month and day.
minify code