1. JavaScript does not have a basic date data type, so you can only create Date objects explicitly. For example: var myDate=new Date();
2. In order to create a Date object that stores a specific date or time, you can simply put the date or date and time in brackets;
var myDate=new Date("2015/06/16 10:30"); alert(myDate);
The effect displayed by Firefox browser is:
IE browser display effect:
The display effect of Google Chrome is:
Note: If the above code is written like this; an error will be reported in Firefox and IE browsers:
var myDate=new Date("2015-06-16 10:30"); alert(myDate);
IE browser error message:
Firefox browser error message:
3. Different countries use different orders to describe dates, eg. The date format set by the United States is MM/DD/YY, while the European format is DD/MM/YY, and in the motherland, their format is YY/MM. /DD. If using an abbreviated name to specify the month. Then you can use them in any order.
For example:
var myDate=new Date("Jun 16 2015") alert(myDate); var myDate=new Date(" 16 Jun 2015") alert(myDate); var myDate=new Date("2015 16 Jun ") alert(myDate);
The displayed order is: month, day, year
Firefox display effect:
IE display effect:
Google display effect:
4.Date object, there are many parameters, var myDate=new Date(aYear,aMonth,aDate,aHour,aMinute,aSecond,aMillisecond);
To use these parameters, you first need to specify the year and month, and then use these parameters, but they must be used in order, one by one and you cannot choose between them.
For example: you can specify the year, month, date, and hour; but you cannot specify the year, month, and then the hour.
This is wrong to write. At this time, the date cannot be enclosed in double quotes:
var myDate=new Date("2015 ,9, 16 ,23"); alert(myDate);
Also at this time, numbers and month abbreviations cannot be mixed. This is also wrong and an error will be reported in IE and Firefox.
var myDate=new Date("2015 ,Jun, 16 ,23"); alert(myDate);
Instead it should be written like this:
var myDate=new Date(2015 ,9, 16 ,23); alert(myDate);
*But you cannot specify the year, month, and then the hour.
For example: 14 here originally refers to 14 o'clock, but now it becomes a date because there is no specified date. . .
var myDate=new Date("2015 ,7, ,14"); alert(myDate);
Firefox renderings:
In IE, an error will be reported directly:
In Google, it’s like this. . :
5. Although we usually think of September as the ninth month, Javascript starts counting months from 0 (January), so month 8 means September.
The above is the entire content of this article, I hope you all like it.