1, Date.now ()
// Date.now () is in ECMAScript 5 // Prior to, use +new Date () // get current time var now = (typeof Date.now = = "function"?) Date.now (): +new Date ()); Alert ("right now:" + now);
2. Date.parse () method
var New Date (); alert (now); var New Date (Date.parse ("May, 2004")); // The parse () method resolves a datetime string and returns the number of milliseconds between midnight of 1970/1/1 and the date time. alert (somedate);
3, Date UTC (), and toutcstring () methods
//the UTC () method returns the number of milliseconds from January 1, 1970 to the specified date, depending on the time. //DATE.UTC (year,month,day,hours,minutes,seconds,ms) /*Year required. A four-digit number that represents the year. Month is required. An integer that represents the month, between 0 and 11. Day required. An integer representing the date, between 1 and 31. Hours is optional. An integer representing the hour, between 0 and 23. Minutes is optional. An integer representing the minute, between 0 and 59. Seconds is optional. An integer representing seconds, between 0 and 59. MS is optional. An integer representing milliseconds between 0 and 999. DATE.UTC () is a static method because it needs to be called using the constructor date () instead of a Date object. The parameters of the DATE.UTC () method specify the date and time, which are all UTC times in the GMT time zone. The specified UTC time is converted into milliseconds, so that the constructor Date () and Method Date.settime () can use it. */ //The toutcstring () method converts a Date object to a string based on Universal Time (UTC) and returns the result. //January 1 at midnight varY2K =NewDate (DATE.UTC (2000, 0)); Alert (y2k.toutcstring ()); //May 5, 2005 at 5:55:55 PM GMT varAllfives =NewDate (DATE.UTC (2005, 4, 5, 17, 55, 55)); Alert (allfives.toutcstring ());
JavaScript Learning Summary (iv) Date object