JavaScript facilitates an object especially to get a day, a month, or a year as an output. This object is also called a JavaScript Date object.
JavaScript date object constructors
Date() Date(milliSeconds) Date(dateString) Date(year, month, day, hours, minutes, seconds, milliSeconds)
Example:
<html> <body> <script> var date=new Date(); var day=date.getDate(); var month=date.getMonth()+1; var year=date.getFullYear(); document.write("<br>Today Date: "+date); document.write("<br>Day: "+day); document.write("<br>Month: "+month); document.write("<br>Year: "+year); </script> </body> </html>
JavaScript Date Methods:
getDate() method: Use: To get the integer value between 1 and 31 that represents the day for the particular date on the basis of local time.
getDay() method: Use: To get the integer value between 0 and 6 that represents the day of the week on the basis of local time.
getFullYear() method: Use: To get the integer value that represents the year on the basis of local time.
getHours() method: Use: To get the integer value between 0 and 23 that represents the hours on the basis of local time.
getMilliseconds() method: Use: To get the integer value between 0 and 999 that represents the milliseconds on the basis of local time.
getMinutes() method: Use: To get the integer value between 0 and 59 that represents the minutes on the basis of local time.
getMonth() method: Use: To get the integer value between 0 and 11 that represents the month on the basis of local time.
getSeconds() method: Use: To get the integer value between 0 and 60 that represents the seconds on the basis of local time.
getUTCDate() method: Use: To get the integer value between 1 and 31 that represents the day for the particular date on the basis of universal time.
getUTCDay() method: Use: To get the integer value between 0 and 6 that represents the day of the week on the basis of universal time.
getUTCFullYear() method: Use: To get the integer value that represents the year on the basis of universal time.
getUTCHours() method: Use: To get the integer value between 0 and 23 that represents the hours on the basis of universal time.
getUTCMinutes() method: Use: To get the integer value between 0 and 59 that represents the minutes on the basis of universal time.
getUTCMonth() method: Use: To get the integer value between 0 and 11 that represents the month on the basis of universal time.
getUTCSeconds() method: Use: To get the integer value between 0 and 60 that represents the seconds on the basis of universal time.
setDate() method: Use: To set the day value for the particular date on the basis of local time.
setFullYear() method: Use: To set the year value for the particular date on the basis of local time.
setHours() method: Use: To set the hour value for the particular date on the basis of local time.
setMilliseconds() method: Use: To set the millisecond value for a particular date on the basis of local time.
setMinutes() method: Use: To set the minute value for the particular date on the basis of local time.
setMonth() method: Use: To set the month value for the particular date on the basis of local time.
setSeconds() method: Use: To set the second value for the particular date on the basis of local time.
setUTCDate() method: Use: To set the day value for a particular date on the basis of universal time.
setUTCFullYear() method: Use: To set the year value for the particular date on the basis of universal time.
setUTCHours() method: Use: To set the hour value for a particular date on the basis of universal time.
setUTCMilliseconds() method: Use: To set the millisecond value for a particular date on the basis of universal time.
setUTCMinutes() method: Use: To set the minute value for a particular date on the basis of universal time.
setUTCMonth() method: Use: To set the month value for the particular date on the basis of universal time.
setUTCSeconds() method: Use: To set the second value for the particular date on the basis of universal time.
toDateString() method: Use: To get the date portion of a Date object.
toISOString() method: Use: To get the date in the form ISO format string.
toJSON() method: Use: To get a string representing the Date object and serializing the Date object at the time of JSON serialization.
toString() method: Use: To get the date in the form of a string.
toTimeString() method: Use: To get the time portion of a Date object.
toUTCString() method: Use: To get the particular date in the form of a string using UTC time zone.
valueOf() method: Use: To get the primitive value of a Date object.