In javascript, the Date () function is displayed in various browsers.

Source: Internet
Author: User

In javascript, the Date () function is displayed in various browsers.

1. JavaScript does not have a basic Date data type, so you can only explicitly create a Date object. For example, var myDate = new Date ();

2. 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);

Firefox displays the following results:

IE Browser display:

Google Chrome displays the following results:

Note: If the above Code is written like this, an error is reported in Firefox and IE:

var myDate=new Date("2015-06-16 10:30");alert(myDate);

Internet Explorer error message:

Firefox browser error message:

3. different countries use different order to describe the date. in the United States, the date format is MM/DD/YY, while in Europe, the date format is DD/MM/YY. In the motherland, their format is YY/MM/DD. If you use the abbreviated name to specify a month. It can be used 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);

That is, the display order is: month, day, year

Firefox display:

IE display effect:

Google display:

4. Date object, there are many parameters, var myDate = new Date (aYear, aMonth, aDate, aHour, aMinute, aSecond, aMillisecond );

To use these parameters, you must first specify the year and month, and then use these parameters, but they must be used in order and cannot be selected one by one.

For example, you can specify the year, month, date, and hour. However, you cannot specify the year, month, or hour.

In this case, it is wrong to write. In this case, double quotation marks cannot be used to enclose the date:

var myDate=new Date("2015 ,9, 16 ,23");alert(myDate);

In this case, the combination of numbers and abbreviated month is not allowed. This is also an error and an error is reported in IE and Firefox.

var myDate=new Date("2015 ,Jun, 16 ,23");alert(myDate);

But we should write it like this:

var myDate=new Date(2015 ,9, 16 ,23);alert(myDate);

* The year, month, and hour cannot be specified.

For example, here 14 originally refers to, but now it is changed to a date because no date is specified...

var myDate=new Date("2015 ,7, ,14");alert(myDate);

Firefox:

In IE, an error is reported directly:

In Google, this is the case .. :

5. Although we usually think that September is the ninth month, Javascript starts to calculate the month from 0 (September), so month 8 indicates January.

The above is all the content of this article. I hope you will like it.

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.