Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Date Object Complete Reference

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 10 Jan, 2023
Improve Article
Save Article

The Date object in JavaScript is used to represent a moment in time It is used to work with date and time This time value is since 1 January 1970 UTC (Coordinated Universal Time) 

 

Syntax:

new Date();

Example 1: If nothing as the parameter is given, it returns the present date and time

Javascript




<script>
    // If nothing as a parameter is given,
    // it represents the present date and time.
    var A = new Date();
      
    // Printing present date and time.
    console.log(A);
</script>

Output:

Mon Nov 14 2022 16:56:38 GMT+0530 (India Standard Time)

The complete list of JavaScript properties and functions & properties are listed below:

JavaScript  Date Object Properties

Properties

Description

constructorReturns the constructor function for an object.
prototype Represents the prototype for the Date constructor.

JavaScript  Date Object Functions:

 Functions

Description 

getDate() Fetch the date of a month from a given Date object.
getDay() Fetch the day of a week(0 to 6) from a given Date object.
getFullYear()Fetch the year from a given Date object.
getHours() Return the hours from a given Date object.
getMilliseconds()Fetch the milliseconds from a given Date object.
getMinutes()Fetch the minutes from the given Date object .
getMonth()Fetch the month(0 to 11) from the given Date object.
getSeconds()Fetch the seconds from the given Date object.
getTime()Return the number of milliseconds since 1 January 1970 .
getTimezoneOffset()Return the time difference between in minutes.
getUTCDate() Fetch the date of a month according to universal time from a given Date object.
getUTCDay()Fetch the date of a month according to universal time from a given Date object.
getUTCFullYear() Fetch the year according to universal time from a given Date object.
getUTCHours()Fetch the hours according to universal time from a given Date object.
getUTCMilliseconds()Fetch the millisecond according to universal time from a given Date object.
getUTCMinutes()Fetch the minutes according to universal time from a given Date object.
getUTCMonth()Fetch the month according to universal time from a given Date object.
getUTCSeconds()Fetch the second according to universal time from a given Date object
now()Return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
parse()Return the time difference in milliseconds from, January 1, 1970, till the date we provide.
setDate()Set date of a month into a date object which is created using date() constructor.
setFullYear()Set year into a date object which is created using Date() constructor.
setHours() Set hours into a date object which is created using the Date() constructor.
setMilliseconds()Set milliseconds into a date object which are created using date() constructor.
setMinutes()Set minutes into a Date object which is created using Date() constructor.
setMonth() Set month into a date object which is created using the Date() constructor.
setSeconds()Set seconds into a Date object which is created using Date() constructor.
setUTCDate()Set date of a month according to universal time into a date object.
setUTCFullYear()Set year into a date object according to universal time.
setUTCHours()Set hours into a date object according to universal time.
setUTCMilliseconds() Set milliseconds according to universal time into a date object.
setUTCMinutes() Set minutes according to universal time into a date object.
setUTCMonth()Set month according to universal time into a date object.
setUTCSeconds()Set seconds according to universal time into a date object.
toDateString()Convert the given date object’s contents of the date portion into a string.
toISOString() Convert the given date object’s contents into a string in ISO format (ISO 8601).
toJSON()Convert the given date object’s contents into a string.
toLocaleDateString()  Convert a date to a string.
toLocaleTimeString() Fetch the time from a given Date object.
toLocaleString()Convert a date and time to a string.
toString()Convert the given date object’s contents into a string.
toTimeString()Return the time portion of the given date object in English.
toUTCString()Convert the given date object’s contents into a string according to the universal time zone UTC.
UTC()Return the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.
valueOf()Get the number of milliseconds between 1 January 1970 00:00:00 UTC and the given date.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!