5 ways in JS initialization date Date

Original: 5 Ways JS initialization date in date

Create a Date Object:
code is as follows:

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

There are five kinds of parameters in the form:

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 is always displayed in the program parameter format is incorrect, it must be carefully looked at integer can I pass a string

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

Note that the last form, parameter indicates the number of milliseconds between January 1, 1970 and the time needed to create the GMT time. The meaning of the function is as follows:

month: the month name in English, from January to December

mth: the month as an integer, from (January) to 11 (December)

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

yyyy: Year represented by four digits

hh: hours, from 0 (midnight) to 23 (11 pm)

mm: minutes, an integer from 0 to 59

ss: seconds, an integer from 0 to 59

ms: milliseconds, is an integer of 0

Such as:
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);

Various forms created above have said, 2006 January 12 that day.

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12604454.html