JavaScript Date knowledge analysis, javascriptdate

Source: Internet
Author: User

JavaScript Date knowledge analysis, javascriptdate

Date function

  • New Date ()

The Date object automatically saves the current Date and time as its initial value.

  • Date. getDate ()

Returns a day of a month from the Date object (1 ~ 31 ).

  • Date. getDay ()

Returns a day of the week from the Date object (0 ~ 6 ). Sunday is 0.

  • Date. getMonth ()

Returns the month from the Date object (0 ~ 11 ).

  • Date. getFullYear ()

Returns the year from the Date object with four digits

  • Date. getHours ()

Returns the hour of the Date object (0 ~ 23 ).

  • Date. getMinutes ()

Returns the minute of the Date object (0 ~ 59 ).

  • Date. getSeconds ()

Returns the number of seconds of the Date object (0 ~ 59 ).

  • Date. getMilliseconds ()

Returns the millisecond of the Date object (0 ~ 999 ).

  • Date. getTime ()

Returns the number of milliseconds since January 1, January 1, 1970.

  • Date. getTimezoneOffset ()

Returns the time difference between Greenwich Mean Time (GMT or UTC) and the local time, in minutes. The reason why the returned results are measured in minutes instead of hours is that

The time zone occupied by the country is less than an hour.

  • Date. getUTCDate ()

Returns the Day (1 ~ 31 ).

  • Date. getUTCDay ()

Returns the day of the week (0 ~ 6 ). Sunday is 0.

  • Date. getUTCMonth ()

Returns the month (0 ~ 11 ).

  • Date. getUTCFullYear ()

Returns the four-digit year from the Date object based on the universal time.

  • Date. getUTCHours ()

Returns the hour of the Date object based on the Universal Time (0 ~ 23 ).

  • Date. getUTCMinutes ()

Returns the minute of the Date object based on the Universal Time (0 ~ 59 ).

  • Date. getUTCSeconds ()

Returns the second of the Date object based on the Universal Time (0 ~ 59 ).

  • Date. getUTCMilliseconds ()

Returns the millisecond of the Date object based on the Universal Time (0 ~ 999 ).

  • Date. parse (string)

Returns the number of milliseconds from midnight, January 1, January 1, 1970 to the specified date (string.

  • Date. setDate (int)

Set a day of the month in the Date object (1 ~ 31 ). Returns the millisecond representation of the adjusted date.

  • Date. setMonth (month [, day])

Set the month (0 ~ 11 ). The day parameter is optional, indicating that the day of the month is between 1 ~ Between 31.

  • Date. setFullYear (year [, month, day])

Set the year (four digits) in the Date object ). The month parameter is optional, indicating that the month is between 0 and ~ Between 11. The day parameter is optional, indicating that the day of the month is between 1 ~ Between 31.

  • Date. setHours (hours [, minutes, seconds, milliseconds])

Set the hour in the Date object (0 ~ 23 ). The minutes parameter is optional, indicating that the number of minutes is between 0 and ~ Between 59. The seconds parameter is optional, indicating that the number of minutes is between 0.

~ Between 59. The milliseconds parameter is optional, indicating that the number of minutes is between 0 and ~ In the range of 999.

  • Date. setMinutes (minutes [, seconds, milliseconds])

Set the minute in the Date object (0 ~ 59 ). The seconds parameter is optional, indicating that the number of minutes is between 0 and ~ Between 59. The milliseconds parameter is optional, indicating that the number of minutes is between 0 and ~ In the range of 999.

  • Date. setSeconds (seconds [, milliseconds])

Set the second in the Date object (0 ~ 59 ). The milliseconds parameter is optional, indicating that the number of minutes is between 0 and ~ In the range of 999.

  • Date. setMilliseconds (int)

Set the millisecond in the Date object (0 ~ 999 ).

  • Date. setTime (long)

The number of milliseconds between the specified date and time according to the GMT time between midnight, January 1, January 1, 1970. Represents a date in milliseconds to make it independent of the time zone.

  • Date. setUTCDate (int)

Set the day of the month in the Date object according to the Universal Time (1 ~ 31 ).

  • Date. setUTCMonth (minutes [, seconds, milliseconds])

Set the month in the Date object according to the Universal Time (0 ~ 11 ). The seconds parameter is optional, indicating that the number of minutes is between 0 and ~ Between 59. Optional milliseconds parameters, table

The number of minutes is between 0 and ~ In the range of 999.

  • Date. setUTCFullYear (year [, month, day])

Set the year (four digits) in the Date object according to the Universal Time ). The month parameter is optional, indicating that the month is between 0 and ~ Between 11. The day parameter is optional.

One day is between 1 ~ Between 31.

  • Date. setUTCHours (hours [, minutes, seconds, milliseconds])

Set the hour in the Date object according to the Universal Time (0 ~ 23 ). The minutes parameter is optional, indicating that the number of minutes is between 0 and ~ Between 59. Seconds parameter (optional)

The number of minutes is between 0 and ~ Between 59. The milliseconds parameter is optional, indicating that the number of minutes is between 0 and ~ In the range of 999.

  • Date. setUTCMinutes (minutes [, seconds, milliseconds])

Set the minute in the Date object according to the Universal Time (0 ~ 59 ). The seconds parameter is optional, indicating that the number of minutes is between 0 and ~ Between 59. Optional milliseconds parameters, table

The number of minutes is between 0 and ~ In the range of 999.

  • Date. setUTCSeconds (seconds [, milliseconds])

Set the second in the Date object according to the Universal Time (0 ~ 59 ). The milliseconds parameter is optional, indicating that the number of minutes is between 0 and ~ In the range of 999.

  • Date. setUTCMilliseconds (int)

Set the millisecond in the Date object according to the Universal Time (0 ~ 999 ).

  • Date. toString ()

Converts a Date object to a string.

  • Date. toTimeString ()

Converts the time part of the Date object to a string.

  • Date. toDateString ()

Converts the Date part of the Date object to a string.

  • Date. toUTCString ()

Converts a Date object to a string based on the universal time.

  • Date. toLocaleString ()

Converts a Date object to a string based on the local time format.

  • Date. toLocaleTimeString ()

Converts the time part of the Date object to a string based on the local time format.

  • Date. toLocaleDateString ()

Converts the Date part of the Date object to a string based on the local time format.

  • Date. UTC (year, month, day [, hour, minute, second, milliseconds])

Returns the number of milliseconds from January 1, January 1, 1970 to the specified date based on the universal time. Year, month, and day are required, and the time, minute, and second are optional.

  • Date. valueOf ()

Returns the original value of the Date object. It is equal to the value returned by Date. getTime. That is, the number of milliseconds since January 1, January 1, 1970.

<Html> 

Format Date

Because JS does not provide date formatting functions. Therefore, you must use the prototype attribute to add custom date formatting methods.

<Html> 

Set parameters out of range for Date

No error is reported even if the parameter is set to be out of the range. Only the date value after the sum of "Maximum valid value" and "exceeding value" is calculated.

Increase or decrease Date

Compare Date

<Html> 

The above is an analysis of the JavaScript Date knowledge introduced by xiaobian. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in time!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.