A day of JavaScript learning Summary (Date object) _javascript tips

Source: Internet
Author: User
Tags gmt time zone current time

1, Date.now ()

 Date.now () is in ECMAScript 5
    //prior to, use +new Date ()
    //Get current time
    var now = (typeof Date.now = = "Funct Ion "? Date.now (): +new Date ());
    Alert ("Right now:" + now);

2, Date.parse () method

var now = new Date ();
  alert (now);
  
  var somedate = new Date (Date.parse ("May)");
  The parse () method resolves a date-time string and returns the number of milliseconds from the 1970/1/1 midnight distance from that date time.
  alert (somedate);

3, Date UTC () and toutcstring () methods

The UTC () method returns the number of milliseconds from January 1, 1970 to a specified date based on the universal.
  //DATE.UTC (YEAR,MONTH,DAY,HOURS,MINUTES,SECONDS,MS)/
  * is
   required. Represents a four-digit number for the year.
   month required. An integer representing the month, between 0 ~ 11. Day
   required. An integer representing the date, between 1 ~ 31.
   hours optional. An integer that represents the hour, between 0 ~ 23.
   minutes optional. An integer that represents the minute, between 0 ~ 59.
   seconds optional. An integer representing the second, between 0 ~ 59.
   Ms Optional. An integer representing milliseconds, between 0 ~ 999.
   DATE.UTC () is a static method because it needs to be invoked by using the constructor date (), rather than by a Date object.
   the parameters of the DATE.UTC () method specify the date and time, which are in UTC time and in GMT time zone. The specified UTC time is converted to milliseconds, so that
   the constructor Date () and Method Date.settime () can be used. The
  *
  
  ///toutcstring () method converts a Date object to a string based on Universal Time (UTC) and returns the result.
  
  //january 1 at midnight
  var y2k = new Date (DATE.UTC (0));
  Alert (y2k.toutcstring ());
  
  May 5, 5:55:55 PM GMT
  var allfives = new Date (DATE.UTC (4, 5, MB,));
  Alert (allfives.toutcstring ());

The above is today's JavaScript learning Summary, and will continue to update every day, I hope you continue to pay attention.

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.