Five methods for date initialization of js data

Source: Internet
Author: User

Create a date object:
Copy codeThe Code is as follows:
Var objDate = new Date ([arguments list]);

The following five parameters are supported:

1) new Date ("month dd, yyyy hh: mm: ss ");
2) new Date ("month dd, yyyy ");
3) new Date (yyyy, mth, dd, hh, mm, ss );

The third initialization method I used in the program always shows that the formatting parameters are incorrect. After carefully reading the information, it must be an integer. What I pass is a string.

4) new Date (yyyy, mth, dd );
5) new Date (MS );

Note the last form. The parameter represents the number of milliseconds between the creation time and the GMT time of January 1, January 1, 1970. The meanings of various functions are as follows:

Month: represents the name of a month in English, from January to December.

Mth: an integer representing the month, from (January 1, January) to 11 (January 1, December)

Dd: the day of a month, from 1 to 31.

Yyyy: The Year in four-digit format.

Hh: hours, from 0 (midnight) to 23)

Mm: The number of minutes, an integer from 0 to 59.

Ss: number of seconds, an integer from 0 to 59

Ms: Number of milliseconds, an integer greater than or equal to 0

For example:
Copy codeThe Code is as follows:
New Date ("January 12,2006 22:19:35 ");

New Date ("January 12,2006 ");

New Date );

New Date (2007,0, 12 );

New Date (1137075575000 );

All the above creation forms indicate the day of June 1, January 12, 2006.

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.