Home > Web Front-end > Front-end Q&A > What are the date and time methods in javascript

What are the date and time methods in javascript

青灯夜游
Release: 2023-01-07 11:47:31
Original
1946 people have browsed it

Date and time methods include: Date(), getHours(), getMinutes(), getSeconds(), getMilliseconds(), getTime(), getTimezoneOffset(), parse(), setHours(), etc.

What are the date and time methods in javascript

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

Date and time methods in javascript

Method Description
Date() Returns the date and time of the current day.
getDate() Returns the day of the month (1 ~ 31) from the Date object.
getDay() Returns the day of the week (0 ~ 6) from the Date object.
getMonth() Returns the month (0 ~ 11) from the Date object.
getFullYear() Returns the year as a four-digit number from a Date object.
getYear() Please use getFullYear() method instead.
getHours() Returns the hours (0 ~ 23) of the Date object.
getMinutes() Returns the minutes (0 ~ 59) of the Date object.
getSeconds() Returns the number of seconds in the Date object (0 ~ 59).
getMilliseconds() Returns the milliseconds (0 ~ 999) of the 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 the Date object based on universal time.
getUTCDay() Returns the day of the week (0 ~ 6) from the Date object based on universal time.
getUTCMonth() Returns the month (0 ~ 11) from the Date object according to 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.
getUTCMinutes() Returns the minutes (0 ~ 59) of the Date object according to universal time.
getUTCSeconds() Returns the seconds (0 ~ 59) of the Date object according to universal time.
getUTCMilliseconds() Returns the milliseconds (0 ~ 999) of the Date object according to universal time.
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.
setMonth() Set the month (0 ~ 11) in the Date object.
setFullYear() Set the year (four digits) in the Date object.
setYear() Please use the setFullYear() method instead.
setHours() Set the hours (0 ~ 23) in the Date object.
setMinutes() Set the minutes (0 ~ 59) in the Date object.
setSeconds() Set the seconds (0 ~ 59) in the Date object.
setMilliseconds() Set the milliseconds (0 ~ 999) in the Date object.
setTime() Sets the Date object in milliseconds.
setUTCDate() Sets the day of the month (1 ~ 31) in the Date object according to universal time.
setUTCMonth() Set the month (0 ~ 11) 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.
setUTCMinutes() Set the minutes (0 ~ 59) in the Date object according to universal time.
setUTCSeconds() Sets the seconds (0 ~ 59) in the Date object according to universal time.
setUTCMilliseconds() Sets the milliseconds (0 ~ 999) in the Date object according to universal time.
toSource() Returns the source code of the object.
toString() Convert a Date object to a string.
toTimeString() Convert the time part of the Date object to a string.
toDateString() Convert the date part of the Date object to a string.
toGMTString() Please use toUTCString() method instead.
toUTCString() Convert a Date object to a string according to universal time.
toLocaleString() Convert the Date object to 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.
toLocaleDateString() Convert the date part of the Date object into a string according to the local time format.
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.

[Recommended learning: javascript advanced tutorial]

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template