JS new Date () description

Source: Internet
Author: User
Tags local time

JavaScript UTC () method:

The UTC () method returns the number of milliseconds from January 1, 1970 to the specified date, depending on the time.

To create a Date object, you can use the following methods:

var now=new Date ();

No arguments are passed in the function, indicating that this object now automatically obtains the current time.

If you want to create an object with a custom time, you pass the argument to date (). This parameter must be the number of milliseconds (the number of milliseconds from midnight January 1, 1970 UTC to the custom time).

We can use Date.parse () and DATE.UTC () to get the number of milliseconds for a custom time.

date.parse () receives a string parameter that represents a date, such as "may 25,2013", "6/13/2013" and other formats, depending on the locale.

The parameters that are received in DATE.UTC () are the year, the number of months starting from 0 (0-11), the Day of the month (1-31), The Hour Tree (0-23), the minute, the second, and the milliseconds, where the year and the number of months are mandatory, and the other parameters are 0 by default.

Now, if we want to define a date object for December 12, 2013, you can use Date.parse ():
var mydate=new Date (Date.parse ("12/12/2013")),
If so:
var mydate=new date ("12/12/2013"), when the date is constructed, the Date.parse () is automatically called to convert the day string to the number of milliseconds.

You can also use DATE.UTC ():

var mydate=new date (DATE.UTC (2013,11,12)//Note month subscript starting from 0, and day subscript starting from 1
If so:
var mydate=new date (2013,11,12), similar to the constructor method of the above parse, will automatically call DATE.UTC () when constructing the Date object, if the first parameter is a numeric value, it is the year, and the second argument is the month ... However, it is important to note that the former var mydate=new date (DATE.UTC (2013,11,12) is GMT time, and the latter var mydate=new date (2013,11,12) is based on the local time set by the system.

JS new Date () description

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.