YouTip LogoYouTip

Jsref Obj Date

Date Object

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

Create a Date object: new Date()

The following four methods can also be used to create a Date object:

var d = new Date();
var d = new Date(milliseconds); // Parameter is milliseconds
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
  • The milliseconds parameter is a Unix timestamp β€” an integer value representing the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC (the Unix epoch).
  • The dateString parameter is a string representation of a date.
  • The year, month, day, hours, minutes, seconds, and milliseconds parameters represent year, month, day, hour, minute, second, and millisecond, respectively.

For a more comprehensive guide on dates and practical examples, please refer to the JavaScript Date Object Tutorial.

Date Object Properties

Property Description
constructor Returns a reference to the Date function that created this object.
prototype Enables you to add properties and methods to objects.

Date Object Methods

Method Description
getDate() Returns the day of the month (1 ~ 31) from a Date object.
getDay() Returns the day of the week (0 ~ 6) from a Date object.
getFullYear() Returns the year (four digits) from a Date object.
getHours() Returns the hour (0 ~ 23) from a Date object.
getMilliseconds() Returns the milliseconds (0 ~ 999) from a Date object.
getMinutes() Returns the minutes (0 ~ 59) from a Date object.
getMonth() Returns the month (0 ~ 11) from a Date object.
getSeconds() Returns the seconds (0 ~ 59) from a Date object.
getTime() Returns the number of milliseconds since January 1, 1970.
getTimezoneOffset() Returns the difference in minutes between local time and Greenwich Mean Time (GMT).
getUTCDate() Returns the day of the month (1 ~ 31) from a Date object, according to universal time.
getUTCDay() Returns the day of the week (0 ~ 6) from a Date object, according to universal time.
getUTCFullYear() Returns the year (four digits) from a Date object, according to universal time.
getUTCHours() Returns the hour (0 ~ 23) from a Date object, according to universal time.
getUTCMilliseconds() Returns the milliseconds (0 ~ 999) from a Date object, according to universal time.
getUTCMinutes() Returns the minutes (0 ~ 59) from a Date object, according to universal time.
getUTCMonth() Returns the month (0 ~ 11) from a Date object, according to universal time.
getUTCSeconds() Returns the seconds (0 ~ 59) from a Date object, according to universal time.
getYear() Deprecated. Use getFullYear() instead.
parse() Returns the number of milliseconds between midnight of January 1, 1970 and the specified date (as a string).
setDate() Sets the day of the month (1 ~ 31) for a Date object.
setFullYear() Sets the year (four digits) for a Date object.
setHours() Sets the hour (0 ~ 23) for a Date object.
setMilliseconds() Sets the milliseconds (0 ~ 999) for a Date object.
setMinutes() Sets the minutes (0 ~ 59) for a Date object.
setMonth() Sets the month (0 ~ 11) for a Date object.
setSeconds() Sets the seconds (0 ~ 59) for a Date object.
setTime() Sets a Date object to a specified number of milliseconds since January 1, 1970.
setUTCDate() Sets the day of the month (1 ~ 31) for a Date object, according to universal time.
setUTCFullYear() Sets the year (four digits) for a Date object, according to universal time.
setUTCHours() Sets the hour (0 ~ 23) for a Date object, according to universal time.
setUTCMilliseconds() Sets the milliseconds (0 ~ 999) for a Date object, according to universal time.
setUTCMinutes() Sets the minutes (0 ~ 59) for a Date object, according to universal time.
setUTCMonth() Sets the month (0 ~ 11) for a Date object, according to universal time.
setUTCSeconds() The setUTCSeconds() method sets the seconds field of a Date object according to universal time (UTC).
setYear() Deprecated. Use setFullYear() instead.
toDateString() Converts the date portion of a Date object into a string.
toGMTString() Deprecated. Use toUTCString() instead.
toISOString() Returns the date as a string, using the ISO standard.
toJSON() Returns the date as a JSON-formatted string.
toLocaleDateString() Converts the date portion of a Date object into a string, using locale-specific formatting.
toLocaleTimeString() Converts the time portion of a Date object into a string, using locale-specific formatting.
toLocaleString() Converts a Date object into a string, using locale-specific formatting.
toString() Converts a Date object into a string.
toTimeString() Converts the time portion of a Date object into a string.
toUTCString() Converts a Date object into a string, according to universal time. Example: var today = new Date(); var UTCstring = today.toUTCString();
UTC() Returns the number of milliseconds between January 1, 1970 and the specified date, according to universal time.
valueOf() Returns the primitive value of a Date object.
now() Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
← Jsref Obj MathJsref Obj Boolean β†’