JavaScript_Date Object Description

Source: Internet
Author: User

Date object constructor

The Date object has multiple constructors.

NewDate () newDate (milliseconds) newDate (datestring) newDate (year, month) newDate (year, month, day) newDate (year, month, day, hours) newDate (year, month, day, hours, minutes) newDate (year, month, day, hours, minutes, seconds) newDate (year, month, day, hours, minutes, seconds, microseconds) date object constructor parameter description

Milliseconds-the number of milliseconds between the start time defined in JavaScript and January 1, January 1, 1970

Datestring-string represents the date and time. This string can be converted using Date. parse ()

Year-four-digit year. If the value is 0-99, add 1900

Month-0 (representing January)-11 (representing the month between December)

Date Between day-1-31

Hours-0 (midnight)-23 hours

Minutes between minutes-0-59

Seconds between seconds-0-59

Microseconds-Number of milliseconds between 0 and

Date object Return Value

If no parameter exists, the current date is returned.

If the parameter is a number, the number is treated as a millisecond value and converted to a date.

If the parameter is a string, the string is treated as a string representation of the date and converted to a date.

You can also use six constructors to precisely define and return time

Example

Vard1 = newDate (); document. write (d1.toString (); vard2 = newDate ("12:12:12); document. write (d2.toString (); vard3 = newDate (2009, 8, 8); document. write (d3.toString (); Date is a built-in object of JavaScript and must be created using the new method.

The representation of the Date object in JavaScript is the number of milliseconds (timestamp) between midnight (GMT) on January 1, January 1, 1970. Here, the internal representation of the Date object is also called the timestamp. You can use getTime () to convert the Date object to the Date timestamp. The setTime () method can convert the Date timestamp to the standard format of Date.

Date function syntax

Date. method Name (parameter 1, parameter 2 ,...); date. method Name (); date indicates an instance of a Date object, date indicates a date object, and Date. the method name calls a member function of the object.

Date. The method name calls the static function of the object.

Example

Vard = newDate (); vard2 = Date. UTC (); functions of JavaScript_Date are classified by function

Date Acquisition Functions

Date () function -- Date object constructor

GetDate () function -- returns the number of days in the month of the date object (1-31)

GetDay () function -- returns the number of days in the week (0-6) of the date object)

GetFullYear () function -- returns the four-digit year in the date object.

GetHours () function -- returns the hour in the date object (0-23)

GetMilliseconds () function -- returns the number of milliseconds in the date object (0-999)

GetMinutes () function -- returns the number of minutes in the date object (0-59)

GetMonth () function -- returns the number of months in the date object (0-11)

GetSeconds () function -- returns the number of seconds in the date object (0-59)

GetTime () function -- returns the timestamp representation (expressed in milliseconds) of the date object)

GetTimezoneOffset () function -- returns the time difference between the local time and the current date in UTC, in minutes

GetUTCDate () function -- returns the Day (1-31) of the month expressed in the World Standard Time (UTC) in the date object)

GetUTCDay () function -- returns the day of the week (0-6) represented by the World Standard Time (UTC) in the date object)

GetUTCFullYear () function -- returns the four-digit year represented by the World Standard Time (UTC) in the date object.

GetUTCHours () function -- returns the number of hours (0-23) represented by the World Standard Time (UTC) in the date object)

GetUTCMilliseconds () function -- returns the number of milliseconds (0-999) represented in the World Standard Time (UTC) in the date object)

GetUTCMinutes () function -- returns the number of minutes (0-59) represented by the World Standard Time (UTC) in the date object)

GetUTCMonth () function -- returns the number of months (0-11) represented in the World Standard Time (UTC) in the date object)

GetUTCSeconds () function -- returns the number of seconds (0-59) represented by the World Standard Time (UTC) in the date object)

GetYear () function -- returns the year of the date object (real year minus 1900)

Date. UTC () function -- returns the number of milliseconds (timestamp) between the date object and the World Standard Time (UTC) midnight, January 1, January 1, 1970)

Date setting functions

SetDate () function -- sets the day of the month in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetFullYear () function -- sets the year, month, and day in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetHours () function -- sets the hour, minute, second, and millisecond of the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetMilliseconds () function -- sets the number of milliseconds of the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetMinutes () function -- sets the minute, second, and millisecond of the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetMonth () function -- sets the month and day in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetSeconds () function -- sets the day of the month in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetTime () function -- sets the date object in milliseconds and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCDate () function -- sets the day of the month expressed in the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCFullYear () function -- sets the year, month, and day represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCHours () function --- sets the hour, minute, second, and millisecond represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCMilliseconds () function -- sets the number of milliseconds expressed in the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCMinutes () function -- sets the minute, second expressed in the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCMonth () function -- sets the month and day represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCSeconds () function -- sets the second in milliseconds represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetYear () function -- set the year of the date object (real year minus 1900)

Date printing functions

ToDateString () function -- returns the string representation of the date part of the date object.

ToGMTString () function -- returns the string representation of the Greenwich Mean Time (GMT) of the date object.

ToLocaleDateString function -- returns the localized string of the date part of the date object.

ToLocaleTimeString function -- returns the localized string of the time part of the date object

ToTimeString () function -- returns the time string of the date object.

ToUTCString function -- returns the string representation of the world standard Time (UTC) of the date object.

Date Parsing Functions

Date. parse () function-parses a Date string and returns the number of milliseconds (timestamp) between the Date and midnight, January 1, January 1, 1970)

Cript_date function by letter

Date () function -- Date object constructor

GetDate () function -- returns the number of days in the month of the date object (1-31)

GetDay () function -- returns the number of days in the week (0-6) of the date object)

GetFullYear () function -- returns the four-digit year in the date object.

GetHours () function -- returns the hour in the date object (0-23)

GetMilliseconds () function -- returns the number of milliseconds in the date object (0-999)

GetMinutes () function -- returns the number of minutes in the date object (0-59)

GetMonth () function -- returns the number of months in the date object (0-11)

GetSeconds () function -- returns the number of seconds in the date object (0-59)

GetTime () function -- returns the timestamp representation (expressed in milliseconds) of the date object)

GetTimezoneOffset () function -- returns the time difference between the local time and the current date in UTC, in minutes

GetUTCDate () function -- returns the Day (1-31) of the month expressed in the World Standard Time (UTC) in the date object)

GetUTCDay () function -- returns the day of the week (0-6) represented by the World Standard Time (UTC) in the date object)

GetUTCFullYear () function -- returns the four-digit year represented by the World Standard Time (UTC) in the date object.

GetUTCHours () function -- returns the number of hours (0-23) represented by the World Standard Time (UTC) in the date object)

GetUTCMilliseconds () function -- returns the number of milliseconds (0-999) represented in the World Standard Time (UTC) in the date object)

GetUTCMinutes () function -- returns the number of minutes (0-59) represented by the World Standard Time (UTC) in the date object)

GetUTCMonth () function -- returns the number of months (0-11) represented in the World Standard Time (UTC) in the date object)

GetUTCSeconds () function -- returns the number of seconds (0-59) represented by the World Standard Time (UTC) in the date object)

GetYear () function -- returns the year of the date object (real year minus 1900)

Date. parse () function-parses a Date string and returns the number of milliseconds (timestamp) between the Date and midnight, January 1, January 1, 1970)

SetDate () function -- sets the day of the month in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetFullYear () function -- sets the year, month, and day in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetHours () function -- sets the hour, minute, second, and millisecond of the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetMilliseconds () function -- sets the number of milliseconds of the date object and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetMinutes () function -- sets the minute, second, and millisecond of the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetMonth () function -- sets the month and day in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetSeconds () function -- sets the day of the month in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetTime () function -- sets the date object in milliseconds and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCDate () function -- sets the day of the month expressed in the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCFullYear () function -- sets the year, month, and day represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCHours () function --- sets the hour, minute, second, and millisecond represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCMilliseconds () function -- sets the number of milliseconds expressed in the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCMinutes () function -- sets the minute, second expressed in the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCMonth () function -- sets the month and day represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetUTCSeconds () function -- sets the second in milliseconds represented by the World Standard Time (UTC) in the date object, and returns the number of milliseconds (timestamp) between the date object and midnight on January 1, January 1, 1970)

SetYear () function -- set the year of the date object (real year minus 1900)

ToDateString () function -- returns the string representation of the date part of the date object.

ToGMTString () function -- returns the string representation of the Greenwich Mean Time (GMT) of the date object.

ToLocaleDateString function -- returns the localized string of the date part of the date object.

ToLocaleTimeString function -- returns the localized string of the time part of the date object

ToTimeString () function -- returns the time string of the date object.

ToUTCString function -- returns the string representation of the world standard Time (UTC) of the date object.

Date. UTC () function -- returns the number of milliseconds (timestamp) between the date object and the World Standard Time (UTC) midnight, January 1, January 1, 1970)

  1. Common JavaScript Regular Expression Verification
  2. 24 tips for beginners of JavaScript
  3. Cookie details in JavaScript
  4. Usage of confirm, alert, and prompt in JavaScript
  5. JavaScript-based REST client framework

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.