On the method of time object in JavaScript _javascript skill

Source: Internet
Author: User
Tags time zones local time

The Date type in ECMAScript is built on the Java.unile.Date class in early Java. This date type uses the number of milliseconds since UTC (Coordinated Universal time, international coordination times) to start at midnight January 1, 1970 to save dates.

In this data storage format, date types can be saved in exactly 285,616 years before or after January 1, 1970

Date.parse (String)

Accept a string parameter that represents the date, and then try to return the number of milliseconds based on that string, and then return NaN

DATE.UTC (year, month[, day, Hour, Min, second, millisecond])

The number of milliseconds to return the corresponding date according to the parameter, only the first two parameters are required, omitting the other parameters are all assumed to be 0

Date.now ()

Returns the number of milliseconds that represent the date and time when this method was invoked

Methods of inheritance

date.tolocalstring ()

Returns the date and time in the format appropriate to the browser settings, depending on the browser

date.tostring ()

Typically returns a date and time with time zone information, where the time is generally expressed in military time (that is, the range of Hours is 0-23), and the format will vary depending on the browser

date.valueof ()

Returns the millisecond representation of a date that can be used to compare date values

Method of date formatting

date.todatestring ()

Displays the day, month, days, and years in an implementation-specific format

date.totimestring ()

Displays time, minutes, seconds, and time zones in an implementation-specific format

date.tolocadatestring ()

Displays the day, month, days, and years in a locale-specific format

date.tolocatimestring ()

Displays time, minutes, and seconds in an implementation-specific format

date.toutcstring ()

Complete UTC date in the implementation-specific format

Date/Time Component method

Here are the ways to get and set specific parts of a date value directly

gettime ()

Returns the number of milliseconds that represent the date, the same as the value returned by the valueof () method

SetTime (MS)

Setting the date in milliseconds will change the entire date

getFullYear ()

Get 4-digit years (for example 2007 instead of just 07)

getUTCFullYear (year)

Returns the 4-digit year of the UTC date

setfullyear (year)

Set the year of the date. The incoming year value must be a 4-digit number (such as 2007 instead of just 07)

setUTCFullYear (year)

Set the year of the UTC date. The incoming year value must be a 4-digit number (such as 2007 instead of just 07)

getmonth ()

Returns the month of the date in which 0 represents January, and 11 means December

getUTCMonth ()

Returns the month of the UTC date, where 0 indicates January, and 11 means December

setmonth (month)

Set the month of the date, where 0 means January, and 11 means December

setUTCMonth (month)

Set the month of the UTC date, where 0 indicates January, and 11 means December

getdate ()

Returns the number of days in the month of the day (1 to 31)

getUTCDate ()

Returns the number of days in the UTC date month (1 to 31)

Setdate (Japan)

Sets the number of days in the date month. If the value passed in exceeds the number of days that should be in the month, increase the month

setUTCDate (Japan)

Sets the number of days in the UTC date month. If the value passed in exceeds the number of days that should be in the month, increase the month

Getday ()

Returns the day of the Week of the week (0 of which means Sunday, 6 is week 6)

getUTCDay ()

Returns the day of the week of the UTC date (0 of which means Sunday, 6 is week 6)

gethours ()

Returns the number of hours in a date (0 to 23)

getutchours ()

Returns the number of hours in UTC date (0 to 23)

sethours (Time)

Set the number of hours in the date. Increases the number of days in the month when the value passed in exceeds 23

setUTCHours (Time)

Sets the number of hours in UTC date. Increases the number of days in the month when the value passed in exceeds 23

getminutes ()

Returns the number of minutes in a date (0 to 59)

getUTCMinutes ()

Returns the number of minutes in UTC date (0 to 59)

setminutes (min)

Set the number of minutes in the date. Increase the number of hours by passing in a value of more than 59

setutcminutes (min)

Sets the number of minutes in the UTC date. Increase the number of hours by passing in a value of more than 59

getseconds ()

Returns the number of seconds in a date (0 to 59)

getUTCSeconds ()

Returns the number of seconds in UTC date (0 to 59)

setseconds (sec)

Set the number of seconds in the date. Increase the number of minutes when the value passed in exceeds 59

setUTCSeconds (sec)

Sets the number of seconds in the UTC date. Increase the number of minutes when the value passed in exceeds 59

getmilliseconds ()

Returns the number of milliseconds in a date

getUTCMilliseconds ()

Returns the number of milliseconds in UTC date

Setmilliseconds (MS)

Set the number of milliseconds in a date

setUTCMilliseconds (MS)

Set the number of milliseconds in UTC date

getTimezoneOffset ()

Returns the number of minutes between local time and UTC time a

The above article on the JavaScript in the time object of the method is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.