5 ways to initialize a js data date

  • 2020-03-30 01:09:25
  • OfStack

Create a date object:
var objDate=new Date([arguments list]); 

There are five parameter forms as follows:

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

The third initialization method I used in the program always showed that the formatted parameters were not correct, and I took a closer look at it. It must be an integer to be able to pass a string

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

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

Month: December, December, December, December, December, December

MTH: an integer for a month, from (January) to (December)

Dd: represents the days of the month, from 1 to 31

Yyyy: the year represented by four digits

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

Mm: minutes, integers from 0 to 59

Ss: number of seconds, integers from 0 to 59

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

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

Each of the above creation forms represents the date January 12, 2006.

Related articles: