JavaScript Learning Summary (iv) Date object

Source: Internet
Author: User
Tags gmt time zone

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

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.