The effect of the date () function in JavaScript on the display in each browser _javascript tips

Source: Internet
Author: User

1.JavaScript does not have a basic date data type, you can only explicitly create a Date object. For example: Var mydate=new Date ();

2. In order to create a Date object that stores specific dates, or times, you can simply put the date or date and time in parentheses;

var mydate=new Date ("2015/06/16 10:30");
alert (mydate);

Firefox browser shows the following effects:

IE browser Display effect:

Google Browser display effect is:

Note: If the above code is written in this way, make an error in Firefox and IE browsers:

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

IE Browser Error tip:

Firefox Browser error Tip:

3. Different countries use different sequences to describe the dates, eg. the date format developed 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. Specify the month if you use a shortened name. Then you can use it in an arbitrary order.

For example:

var mydate=new Date ("June 2015")
alert (mydate);

var mydate=new Date ("June 2015")
alert (mydate);

var mydate=new Date ("2015 June")
alert (mydate);

The order displayed is: Year of the month

Firefox Display effect:

IE Display effect:

Google Display effect:

4.Date objects, 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 those parameters, but you must follow the order and use them one by one to not choose between them.

For example, you can specify the year, month, date, hour, but not the specified year, month, and then specify the hour.

It's wrong to write this, and you can't enclose the date in double quotes:

var mydate=new Date ("2015, 9,");
alert (mydate);

There is also this time, can not be a combination of numbers and months, this is also wrong, in IE and Firefox in the error.

var mydate=new Date ("2015, June,");

alert (mydate);

And it should be written like this:

var mydate=new Date (2015, 9, N);
alert (mydate);

* But you cannot specify a specified year, month, and then specify an hour.

For example: Here the 14 originally refers to 14 points, but now because there is no specified date, become a date ...

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

Firefox Effect chart:

In IE, the error will be directly:

In Google, it's like this. :

5. Although we usually consider September (September) to be the nineth month, JavaScript calculates the month from 0 (January), so the month 8 represents September.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.