Home  >  Article  >  Web Front-end  >  5 ways to initialize js data date_javascript skills

5 ways to initialize js data date_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:06:291526browse

Create a date object:

Copy code The code is as follows:

var objDate=new Date([ arguments list]);

The parameter forms are as follows:

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 use in the program, It always shows that the formatted parameter is incorrect. I looked carefully and it must be an integer. What I passed was the string

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

Please note the last form. The parameter represents the number of milliseconds between the time to be created and January 1, 1970 GMT time. The meanings of various functions are as follows:

month: Use English to represent the month name, from January to December

mth: Use integers to represent the month, from (January) to 11 (December)

dd: indicates the day of the month, from 1 to 31

yyyy: the four-digit year

hh: hour, from 0 (midnight) to 23 (11 p.m.)

mm: minutes, an integer from 0 to 59

ss: seconds, an integer from 0 to 59

ms: milliseconds Number is an integer greater than or equal to 0

such as:
Copy code The code is as follows:

new Date("January 12,2006 22:19:35");

new Date("January 12,2006");

new Date(2006,0, 12,22,19,35);

new Date(2006,0,12);

new Date(1137075575000);

All of the above The creation form all represents the day of January 12, 2006.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn