A case of Nan occurs with the date () method under IE.

Source: Internet
Author: User

Today, in the format of the time, under the IE8 browser encountered a problem of Nan. But there is no problem on the chorme.

Debugging was found to be an issue with parameters passed in the date () method.

After looking for other people's information, especially this article.

Http://www.jb51.net/article/29800.htm.

Find out where the problem lies. But there is a small problem in it.

function Newdate (str) {str = str.split ('-');     var date = new Date ();     Date.setutcfullyear (Str[0], str[1]-1, str[2]);     Date.setutchours (0, 0, 0, 0); return date; }

The default incoming join for STR should be 2015-05-06. It will only be solved if there is a year and a half.

If you want to format only month or year.

You should:

Date.setutcfullyear (Str[0], str[1]-1, str[2]);

Change the parameters to 2 or 1.

Date.setutchours (0, 0, 0, 0);

This sentence depends on your own needs.


This article is from the "work history of the Mo Bo" blog, please be sure to keep this source http://moxiaobo.blog.51cto.com/6784434/1643452

A case of Nan occurs with the date () method under IE.

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.