HTML CSS Bootstrap Javascript Icons Python
JavaScript Reference
Overview
JS Reference
JS Array Object JS Boolean Object JS Date Object JS Style Declaration Object JS Error Object JS Global Object JS Math Object JS Number Object JS String Object JS RegExp Object JS Statements
DOM Reference
DOM Attribute DOM Console DOM Document DOM Element DOM Events DOM Event Objects DOM History DOM HTMLCollection DOM Location DOM Navigator DOM Screen DOM Style DOM Window WEB Storage

JavaScript Date Reference

The Date Object

The Date object is used to work with dates and times.

Date objects are created with new Date() constructor.

Date objects are based on a time value that is the number of milliseconds since 1 January 1970 UTC.

You can use any of the following syntax to create a Date object using Date() constructor.

Note: JavaScript counts months from 0 to 11. That means January is 0 and December is 11.

You can learn more about date and times in our JavaScript Date Tutorial.


Date Object Properties

The following table lists the properties of the Date object:

Property Description
constructor Returns the function that created the prototype of Date object
prototype Allows you to add new properties and methods to an object

Date Object Methods

The following table lists the methods of the Date object:

Method Description
getDate() Returns the day of the month (from 1-31), according to local time
getDay() Returns the day of the week (from 0-6), according to local time
getFullYear() Returns the year (four digits), according to local time
getHours() Returns the hour (from 0-23), according to local time
getMilliseconds() Returns the milliseconds (from 0-999), according to local time
getMinutes() Returns the minutes (from 0-59), according to local time
getMonth() Returns the month (from 0-11), according to local time
getSeconds() Returns the seconds (from 0-59), according to local time
getTime() Returns the number of milliseconds since midnight Jan 1, 1970, 00:00:00 UTC
getTimezoneOffset() Returns the time difference between UTC time and local time, in minutes
getUTCDate() Returns the day of the month (from 1-31), according to universal time
getUTCDay() Returns the day of the week (from 0-6), according to universal time
getUTCFullYear() Returns the year, according to universal time
getUTCHours() Returns the hour (from 0-23), according to universal time
getUTCMilliseconds() Returns the milliseconds (from 0-999), according to universal time
getUTCMinutes() Returns the minutes (from 0-59), according to universal time
getUTCMonth() Returns the month (from 0-11), according to universal time
getUTCSeconds() Returns the seconds (from 0-59), according to universal time
getYear() Deprecated. Use the getFullYear() method instead
setDate() Sets the day of the month of a date object, according to local time
setFullYear() Sets the full year of a date object, according to local time
setHours() Sets the hours of a date object, according to local time
setMilliseconds() Sets the milliseconds of a date object, according to local time
setMinutes() Set the minutes of a date object, according to local time
setMonth() Sets the month of a date object, according to local time
setSeconds() Sets the seconds of a date object, according to local time
setTime() Sets a date to a specified number of milliseconds after/before Jan 1, 1970
setUTCDate() Sets the day of the month of a date object, according to universal time
setUTCFullYear() Sets the year of a date object, according to universal time
setUTCHours() Sets the hours of a date object, according to universal time
setUTCMilliseconds() Sets the milliseconds of a date object, according to universal time
setUTCMinutes() Set the minutes of a date object, according to universal time
setUTCMonth() Sets the month of a date object, according to universal time
setUTCSeconds() Set the seconds of a date object, according to universal time
setYear() Deprecated. Use the setFullYear() method instead
toDateString() Converts the date portion of a Date object into a human readable form
toGMTString() Deprecated. Use the toUTCString() method instead
toISOString() Returns the date as a string, formatted according to ISO standard
toJSON() Returns the date as a string, formatted as a JSON date
toLocaleDateString() Returns the date portion of a Date object as a locally formatted string
toLocaleTimeString() Returns the time portion of a Date object as a locally formatted string
toLocaleString() Converts a Date object to a locally formatted string
toString() Converts a Date object to a string
toTimeString() Converts the time portion of a Date object to a string
toUTCString() Converts a Date object to a string, according to universal time
valueOf() Returns the primitive value of a Date object

Date Static Methods

The Date object also defines three static methods. These methods are invoked through the Date() constructor itself.

Method Description
Date.now() Returns the number of milliseconds since midnight Jan 1, 1970 00:00:00 UTC
Date.parse() Parses a date string and returns the number of milliseconds since Jan 1, 1970, 00:00:00, UTC, with leap seconds ignored
Date.UTC() Returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00