Information stored in Date type: Number of milliseconds since UTC (January 1, 1970 0 o'clock)
To create a Date object:
Using the constructor date ()
A Date object that represents the current number of milliseconds: var now = new Date ();//no parameter Shime the current number of milliseconds
A Date object that represents the specified number of milliseconds: var date1 = new Date (milliseconds);
To obtain the milliseconds method:
Method One: Date.parse (datestring);//datestring is a string representing the local time
The Date.parse () method returns the number of milliseconds that the string corresponds to, or Nan if the string cannot represent the date.
Common strings:
- Month/day/year: 6/18/2004
- Month name Day, year: January 12,2004
- Day of the week abbreviation month: minute: Second time zone: Tue May 2004 00:00:00 GMT-0700 (Beijing time is gmt+0800)
- ECMAScript 5 Standard: yyyy-mm-ddthh:mm:ss.sssz:2013-10-30t00:00:00+0800
Date.parse () Simple usage: var somedate = new Date ("January 12,2004");//Background call Date.parse ()
Method Two: DATE.UTC (year, month (based on 0) [, day = 1, time = 0, min = 0, sec =0, msec =0]);//Parameter is GMT time, not local time
Simple method: var allfives = new Date (2005, 4, 5, 17, 55, 55);//Direct parameter to constructor date (), the argument is local time! The sentence returns local time May 5, 2005 5:55:55
Date Object String method
Returns the local time string:
toLocaleString ()
ToString ()
toDateString ()
toTimeString ()
toLocaleDateString ()
toLocaleTimeString ()
Returns the UTC time String:
toUTCString ()
Read, set DateTime method
Number of milliseconds to read:
Date.now (): Read the number of milliseconds in the moment
ECMAScript 5 Support Browser: Ie9+,firefox 3+,safari3+,opera10.5,chrome
Common applications: Calculate code run time
var start = Date.now ();
DoSomething ();
var stop = Date.now (),
result = Stop-start;
Other browsers:
var start = +new Date ();
DoSomething ();
var stop = +new Date (),
result = Stop-start;
Note: Use unary operator "+" for non-numeric values
Use number () to convert the value:
- False=>0 true=>1
- String: Converting by a set of rules
- Object: Call valueof () if not, call ToString ()
GetTime (): reads the number of milliseconds for a Date object
ValueOf (): reads the number of milliseconds for a Date object
Common applications: Use > < >= <= to compare the size of a Date object (background call valueof ())
var date1 = new Date (2007,0,1);
var date2 = new Date (2007,1,1);
Alert (Date1 < date2);//true
Alert (date1> date2);//false
- Call valueof () if not, call ToString ()
Set Date object milliseconds: SetTime ()
Four-digit year: getFullYear () setfullyear () getUTCFullYear () setUTCFullYear ()
Month: Month (0-11)//DATE.UTC () method is also the monthly parameter 0--11
Date: Date (1-31)
Day of the Week: Day (0-6,0 is Sunday, only get method)
Time: Hour (0--23)
Points: Minutes
Seconds: Seconds
MS: Milliseconds
Time zone skew minutes (UTC time-local time = minutes): getTimezoneOffset ()
"JS Note" 5.3 Date type 5.4 regexp type