Easy Tutorial
❮ Prop Textarea Disabled Prop Button Type ❯

JavaScript Date Object


Date Object

The Date object is used to handle dates and times.

Creating a Date object: new Date()

The following four methods can also 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, which is an integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC (the Unix epoch).

-

The dateString parameter is a string value representing the date.

-

year, month, day, hours, minutes, seconds, milliseconds represent the year, month, day, hour, minute, second, and millisecond, respectively.

For a more complete date and time tutorial, please refer to the JavaScript Date Object Tutorial.


Date Object Properties

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

Date Object Methods

Method Description
getDate() Returns the day of the month from the Date object (1 ~ 31).
getDay() Returns the day of the week from the Date object (0 ~ 6).
getFullYear() Returns the year in four digits from the Date object.
getHours() Returns the hour from the Date object (0 ~ 23).
getMilliseconds() Returns the milliseconds from the Date object (0 ~ 999).
getMinutes() Returns the minutes from the Date object (0 ~ 59).
getMonth() Returns the month from the Date object (0 ~ 11).
getSeconds() Returns the seconds from the Date object (0 ~ 59).
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 from the Date object according to universal time (1 ~ 31).
getUTCDay() Returns the day of the week from the Date object according to universal time (0 ~ 6).
getUTCFullYear() Returns the year in four digits from the Date object according to universal time.
getUTCHours() Returns the hour from the Date object according to universal time (0 ~ 23).
getUTCMilliseconds() Returns the milliseconds from the Date object according to universal time (0 ~ 999).
getUTCMinutes() Returns the minutes from the Date object according to universal time (0 ~ 59).
getUTCMonth() Returns the month from the Date object according to universal time (0 ~ 11).
getUTCSeconds() Returns the seconds from the Date object according to universal time (0 ~ 59).
getYear() Deprecated. Use getFullYear() instead.
parse() Returns the number of milliseconds from midnight of January 1, 1970, to the specified date (string).
setDate() Sets the day of the month in the Date object (1 ~ 31).
setFullYear() Sets the year in the Date object (four digits).
setHours() Sets the hours in the Date object (0 ~ 23).
setMilliseconds() Sets the milliseconds in the Date object (0 ~ 999).
setMinutes() Sets the minutes in the Date object (0 ~ 59).
setMonth() Sets the month in the Date object (0 ~ 11).
setSeconds() Sets the seconds in the Date object (0 ~ 59).
setTime() Sets the Date object in milliseconds.
setUTCDate() Sets the day of the month in the Date object according to universal time (1 ~ 31).
setUTCFullYear() Sets the year in the Date object according to universal time (four digits).
setUTCHours() Sets the hours in the Date object according to universal time (0 ~ 23).
setUTCMilliseconds() Sets the milliseconds in the Date object according to universal time (0 ~ 999).
setUTCMinutes() Sets the minutes in the Date object according to universal time (0 ~ 59).
setUTCMonth() Sets the month in the Date object according to universal time (0 ~ 11).
setUTCSeconds() Sets the seconds in the Date object according to universal time (0 ~ 59).
setYear() Deprecated. Use setFullYear() instead.
toDateString() Converts the date portion of the Date object to a string.
toGMTString() Deprecated. Use toUTCString() instead.
toISOString() Returns the date in ISO standard format.
toJSON() Returns the date as a string in JSON format.
toLocaleDateString() Converts the date portion of the Date object to a string based on local time format.
toLocaleTimeString() Converts the time portion of the Date object to a string based on local time format.
toLocaleString() Converts the Date object to a string based on local time format.
toString() Converts the Date object to a string.
toTimeString() Converts the time portion of the Date object to a string.
toUTCString() Converts the Date object to a string according to universal time. Example: var today = new Date();<br>var UTCstring = today.toUTCString();
UTC() Returns the number of milliseconds from January 1, 1970, to the specified date according to universal time.
valueOf() Returns the primitive value of the Date object.
❮ Prop Textarea Disabled Prop Button Type ❯