Home  >  Article  >  Web Front-end  >  What are the methods of date object in javascript

What are the methods of date object in javascript

青灯夜游
青灯夜游Original
2021-07-06 16:06:337822browse

Methods of date objects: getDate(), getDay(), getFullYear(), getHours(), getMinutes(), getMonth(), getSeconds(), getTime(), parse(), setDate() wait.

What are the methods of date object in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Date object is used to handle date and time.

Methods of date objects in javascript

Method Description
getDate() Returns the day of the month from the Date object One day (1 ~ 31).
getDay() Returns the day of the week (0 ~ 6) from the Date object.
getFullYear() Returns the year as a four-digit number from a Date object.
getHours() Returns the hours (0 ~ 23) of the Date object.
getMilliseconds() Returns the milliseconds (0 ~ 999) of the Date object.
getMinutes() Returns the minutes (0 ~ 59) of the Date object.
getMonth() Returns the month (0 ~ 11) from the Date object.
getSeconds() Returns the number of seconds in 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 (1 ~ 31) from the Date object based on universal time.
getUTCDay() Returns the day of the week (0 ~ 6) from the Date object based on universal time.
getUTCFulYear() Returns the four-digit year from a Date object based on universal time.
getUTCHours() Returns the hour (0 ~ 23) of the Date object according to universal time.
getUTCMilliseconds() Returns the milliseconds (0 ~ 999) of the Date object according to universal time.
getUTCMinutes() Returns the minutes (0 ~ 59) of the Date object according to universal time.
getUTCMonth() Returns the month (0 ~ 11) from the Date object according to universal time.
getUTCSeconds() Returns the seconds (0 ~ 59) of the Date object according to universal time.
getYear() Deprecated. Please use getFullYear() method instead.
parse() Returns the number of milliseconds from midnight on January 1, 1970 to the specified date (string).
setDate() Set a certain day of the month (1 ~ 31) in the Date object.
setFullYear() Set the year (four digits) in the Date object.
setHours() Set the hours (0 ~ 23) in the Date object.
setMilliseconds() Set the milliseconds (0 ~ 999) in the Date object.
setMinutes() Set the minutes (0 ~ 59) in the Date object.
setMonth() Set the month (0 ~ 11) in the Date object.
setSeconds() Set the seconds (0 ~ 59) in the Date object.
setTime() The setTime() method sets a Date object in milliseconds.
setUTCDate() Sets the day of the month (1 ~ 31) in the Date object according to universal time.
setUTCFulYear() Sets the year (four digits) in the Date object according to universal time.
setUTCHours() Sets the hour (0 ~ 23) in the Date object according to universal time.
setUTCMilliseconds() Sets the milliseconds (0 ~ 999) in the Date object according to universal time.
setUTCMinutes() Set the minutes (0 ~ 59) in the Date object according to universal time.
setUTCMonth() Set the month (0 ~ 11) in the Date object according to universal time.
setUTCSeconds() The setUTCSeconds() method sets the seconds field of the specified time based on Universal Time (UTC).
setYear() is obsolete. Please use the setFullYear() method instead.
toDateString() Convert the date part of the Date object to a string.
toGMTString() is obsolete. Please use toUTCString() method instead.
toISOString() Returns the date format of the string using the ISO standard.
toJSON() Returns the date string in JSON data format.
toLocaleDateString() Convert the date part of the Date object into a string according to the local time format.
toLocaleTimeString() Convert the time part of the Date object into a string according to the local time format.
toLocaleString() Convert the Date object to a string according to the local time format.
toString() Convert a Date object to a string.
toTimeString() Convert the time part of the Date object to a string.
toUTCString()

Convert a Date object to a string according to universal time.

Example:

var today = new Date();
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 original value of the Date object.

[Related recommendations: javascript learning tutorial]

The above is the detailed content of What are the methods of date object in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn