A summary of javascript learning every day (Date object) _ javascript skills

Source: Internet
Author: User
Tags gmt time zone
This article mainly introduces the knowledge points of the Date object in javascript, the basic usage of the Date object, and various methods. If you are interested, refer 1. Date. now ()

// Date. now () is in ECMAScript 5 // Prior to that, use + new Date () // obtain the current time var now = (typeof Date. now = "function "? 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 25,200 4"); // The parse () method parses a date and time string and returns the number of milliseconds between and 1 midnight. Alert (someDate );

3. Date UTC () and toUTCString () Methods

// The UTC () method returns the number of milliseconds from January 1, January 1, 1970 to the specified date based on the universal time. // Date. UTC (year, month, day, hours, minutes, seconds, MS)/* year required. Indicates the four-digit number Of The Year. Month is required. Indicates the integer of the month, ranging from 0 ~ 11. Day is required. An integer between 1 and 1 ~ 31. Optional. An integer of the hour, ranging from 0 ~ 23. Minutes is optional. An integer in minutes, ranging from 0 ~ 59. Seconds is optional. An integer in seconds. The value range is 0 ~ 59. Optional MS. An integer in milliseconds, ranging from 0 ~ 999. Date. UTC () is a static method, because it needs to be called using the constructor Date () instead of using a Date object. The parameters of the Date. UTC () method specify the Date and time, both of which are UTC time and are 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, 2000 at midnight var y2k = new Date (Date. UTC (2000, 0); alert (y2k. toUTCString (); // May 5, 2005 at 5:55:55 GMT var allFives = new Date (Date. UTC (2005, 4, 5, 17, 55, 55); alert (allFives. toUTCString ());

The above is the summary of today's javascript learning, and will be updated every day. I hope you will continue to pay attention to it.

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.