JS under Calculate the current date (the day) after the n days of Nan or undefined the case

Source: Internet
Author: User

Objective:

To help customers make an order system, a date of 1, a date of 2, by default, the date 1 is the day, the date 2 for tomorrow, but some doubts that the date 2 occasionally appear Nan, Today I saw the same problem in segmentfault.com, so I think it is necessary to revisit the problem at that time. Do a good job.

<!--date () NAN start-->

The following code is a problem, not recommended for direct use, just temporary version, subsequent modification

<! DOCTYPE html>"en">"UTF-8"> <title>date NaN undefined</title>"Today"></div> <div id="NextDay"></div> <script>varmonth = {        "Jan":" on",        "Feb":" Geneva",        "Mar":"Geneva",        "APR":"Geneva",        " May":" to",        "June":" .",        "Jul":" -",        " the":" ,",        "Sep":" the",        "Oct":"Ten",        "Nov":" One",        "Dec":" A"    }; function GetDate (e) {varD,thedate,array; if(e.time) {varArray =E.time.split (E.symbol); D=NewDate (array[0]+e.symbol+array[1]+e.symbol+ (parseint (array[2])+E.N) ;//There is a serious problem here (this code cannot be used directly)}Else{d=NewDate (); } Array= D.todatestring (). Split (" "); returnarray[3]+e.symbol+month[array[1]]+e.symbol+array[2]; } Today= GetDate ({"symbol":"/"}); document.getElementById ("Today"). InnerHTML =today; document.getElementById ("NextDay"). InnerHTML = GetDate ({"symbol":"/"," Time": Today, "n": 1}); </script></body>

Reason: mainly because IE under only support "/" delimiter.

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.