Introduction to the parameter usage in the DATE function in JS

Source: Internet
Author: User
Tags current time local time numeric value

This article introduces the parameters of the date function in the next JS in detail in the actual use of the introduction, interested friends do not miss

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

The code is as follows:

var now=new Date ()

Of course, no arguments are passed in the function, which means that this object now automatically acquires the current time.

If you want to create an object that is a custom time, you want to pass the parameter to date (). This parameter, however, must be the number of milliseconds (milliseconds from midnight January 1, 1970 to the custom time of the UTC 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 so on, depending on the locale in which the format is supported.

The parameters received in DATE.UTC () are the year, the number of months from 0 (0-11), the Day of the month (1-31), The Hour Tree (0-23), minutes, seconds, milliseconds, where the year and month numbers are required, and the other parameters by default of 0.

Now, if you want to define a date object of 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 invoked to convert the day string to a number of milliseconds.

You can also use DATE.UTC ():

var mydate=new date (DATE.UTC (2013,11,12)/note the month subscript starts with 0, and the subscript of the day starts at 1

If so:

var mydate=new date (2013,11,12), similar to the parse method above, automatically invokes DATE.UTC () when the date object is constructed, if the first argument is a numeric value, it is the year, and the second parameter is the month ... Note, however, that the former var mydate=new date (DATE.UTC (2013,11,12) Gets the GMT time, and the latter var mydate=new date (2013,11,12) Gets the local time based on the system settings.

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.