Javascript built-in object date

Source: Internet
Author: User
Document directory
  • Syntax for creating a date object:

The date object is used to process the date and time.

Syntax for creating a date object:
var myDate=new Date()

Note: The date object automatically saves the current date and time as its initial value.

1 <SCRIPT> 2 var mydate = new date (); 3 // document. write (mydate); 4 var myyear = mydate. getfullyear (); 5 var mymonth = mydate. getmonth () + 1; 6 var mydate1 = mydate. getdate (); 7 var myday = mydate. getday (); 8 If (myday = 0) {9 myday = 7; 10} 11 document. write ("today is" + myyear + "year" + mymonth + "month" + mydate1 + "day," + "Week" + myday); 12 </SCRIPT>
Date object Method

FF: Firefox, ie: Internet Explorer

Method Description FF IE
Date () Returns the date and time of the current day. 1 3
Getdate () Returns a day of a month from the date object (1 ~ 31 ). 1 3
Getday () Returns a day of the week from the date object (0 ~ 6 ). 1 3
Getmonth () Returns the month from the date object (0 ~ 11 ). 1 3
Getfullyear () Returns the year from the date object with four digits. 1 4
Getyear () Use the getfullyear () method instead. 1 3
Gethours () Returns the hour of the date object (0 ~ 23 ). 1 3
Getminutes () Returns the minute of the date object (0 ~ 59 ). 1 3
Getseconds () Returns the number of seconds of the date object (0 ~ 59 ). 1 3
Getmilliseconds () Returns the millisecond of the date object (0 ~ 999 ). 1 4
Gettime () Returns the number of milliseconds since January 1, January 1, 1970. 1 3
Gettimezoneoffset () Returns the minute difference between the local time and Greenwich Mean Time (GMT. 1 3
Getutcdate () Returns the Day (1 ~ 31 ). 1 4
Getutcday () Returns the day of the week (0 ~ 6 ). 1 4
Getutcmonth () Returns the month (0 ~ 11 ). 1 4
Getutcfullyear () Returns the four-digit year from the date object based on the universal time. 1 4
Getutchours () Returns the hour of the date object based on the Universal Time (0 ~ 23 ). 1 4
Getutcminutes () Returns the minute of the date object based on the Universal Time (0 ~ 59 ). 1 4
Getutcseconds () Returns the second of the date object based on the Universal Time (0 ~ 59 ). 1 4
Getutcmilliseconds () Returns the millisecond of the date object based on the Universal Time (0 ~ 999 ). 1 4
Parse () Returns the number of milliseconds from midnight, January 1, January 1, 1970 to the specified date (string. 1 3
Setdate () Set a day of the month in the date object (1 ~ 31 ). 1 3
Setmonth () Set the month (0 ~ 11 ). 1 3
Setfullyear () Set the year (four digits) in the date object ). 1 4
Setyear () Use setfullyear () instead. 1 3
Sethours () Set the hour in the date object (0 ~ 23 ). 1 3
Setminutes () Set the minute in the date object (0 ~ 59 ). 1 3
Setseconds () Set the second in the date object (0 ~ 59 ). 1 3
Setmilliseconds () Set the millisecond in the date object (0 ~ 999 ). 1 4
Settime () Set the date object in milliseconds. 1 3
Setutcdate () Set the day of the month in the date object according to the Universal Time (1 ~ 31 ). 1 4
Setutcmonth () Set the month in the date object according to the Universal Time (0 ~ 11 ). 1 4
Setutcfullyear () Set the year (four digits) in the date object according to the Universal Time ). 1 4
Setutchours () Set the hour in the date object according to the Universal Time (0 ~ 23 ). 1 4
Setutcminutes () Set the minute in the date object according to the Universal Time (0 ~ 59 ). 1 4
Setutcseconds () Set the second in the date object according to the Universal Time (0 ~ 59 ). 1 4
Setutcmilliseconds () Set the millisecond in the date object according to the Universal Time (0 ~ 999 ). 1 4
Tosource () Returns the source code of the object. 1 -
Tostring () Converts a date object to a string. 1 4
Totimestring () Converts the time part of the date object to a string. 1 4
Todatestring () Converts the date part of the date object to a string. 1 4
Togmtstring () Use the toutcstring () method instead. 1 3
Toutcstring () Converts a date object to a string based on the universal time. 1 4
Tolocalestring () Converts a date object to a string based on the local time format. 1 3
Tolocaletimestring () Converts the time part of the date object to a string based on the local time format. 1 3
Tolocaledatestring () Converts the date part of the date object to a string based on the local time format. 1 3
UTC () Returns the number of milliseconds from January 1, January 1, 1970 to the specified date based on the universal time. 1 3
Valueof () Returns the original value of the date object. 1 4

 

 

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.