JS operation date, get the current date, plus one day, minus one day

Source: Internet
Author: User
Use JS in a text box to set the current time, two button, a point add one day, one point to reduce the day.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
   "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">
$ = function (o) {return typeof o = = ' string '? document.getElementById (o): o};
            Set current date var ma = [[' 1 ', ' 3 ', ' 5 ', ' 7 ', ' 8 ', ' 10 '],[' 4 ', ' 6 ', ' 9 ', ' 11 ']];
            var dd = new Date ();
            var x = dd.tolocalestring ();
            var o = pasdate (x);

            $ (' date '). Value = O.join ('-'); 
               Conversion Date function pasdate (DA) {var yp = Da.indexof (' year '), MP = Da.indexof (' month '),
                DP = Da.indexof (' Day '); var y = da.substr (0,yp), M = da.substr (YP + 1,mp-yp-1), D = DA.SUBSTR (MP + 1,dp-mp-1
                );
            return [y,m,d]; //Determine if array a exists in element n function check (n,a) {for var i = 0,len = A.length;i < Len;
                    i++) {if (a[i] = N) {return true;
            return false;
            //Leap year? FUnction isleap (y) {return (y% 4 = 0 && y!= 0) | | y% = = 0)? true:false;
                //implementation plus minus F: ' 1 ' Plus, ' 0 ' minus function trans (o,f) {var d = o.split ('-');

                var L = isleap (d[0]); if (f = = ' 1 ') {if ((check (d[1],ma[0)) && (d[2] = ' 31 ') | |
                              (check (d[1],ma[1]) && (d[2] = = ' 30 ') | | (d[1] = = ' 2 ' && d[2] = = ' &&!l ') | | (d[1] = = ' 2 ' && d[2] = = ' O ' && l))
                    {return d[0] + '-' + (d[1] * 1 + 1) + '-' + 1;
                    else if (d[1] = = ' && d[2] = = ' {return (d[0] * 1 + 1) + '-' + ' 1-1 ';
                    else {return d[0] + '-' + d[1] + '-' + (d[2] * 1 + 1);
   ' Else if ' (f = = ' 0 ') {if (check (d[1]-1,ma[0]) && (d[2] = = ' 1 ')) {                     return d[0] + '-' + (D[1]-1) + '-' + ' 31 ';  ' Else if (check (d[1]-1,ma[1]) && (d[2] = = ' 1 ')) {return d[0] + '-' + (D[1]-1) + '-' +
                    ' 30 ';
                    else if (d[1] = = ' 1 ' && d[2] = = ' 1 ') {return (d[0]-1) + '-' + ' 12-31 ';
                    else if (d[1] = = ' 3 ' && d[2] = = ' 1 ' &&!l) {return d[0] + '-' + ' 2-28 '; else if (d[1] = = ' 3 ' && d[2] = = ' 1 ' && l) {return d[0] + '-'
                    + ' 2-29 ';
                    else {return d[0] + '-' + d[1] + '-' + (D[2]-1);
                } else {return;
                } $ (' Add '). onclick = function () {var v = $ (' date '). Value;
            $ (' date '). Value = trans (V, ' 1 '); } $ (' minus '). onclick = FunCtion () {var v = $ (' date '). Value;
            $ (' date '). Value = trans (V, ' 0 ');         }

Reprint Address: http://www.cnblogs.com/suizhikuo/archive/2011/12/10/2283430.html



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.