码迷,mamicode.com
首页 > 其他好文 > 详细

time

时间:2017-03-09 18:39:03      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:function   today   pre   logs   oda   cas   date()   start   get   

///$.twoDates("startdate",‘enddate‘,3);
$.extend({
    setTwoDates: function (startinputid, endinputid, difference) {

        var year = 0;
        var today = "";
        var mydate = new Date();
        var mymonth = mydate.getMonth() + 1;
        var myday = mydate.getDate();
        var myyear = mydate.getFullYear();
        year = (myyear > 200) ? myyear : 1900 + myyear;
        if (mymonth >= 10) { mymonth = mymonth; } else { mymonth = "0" + mymonth; }
        if (myday >= 10) { myday = myday; } else { myday = "0" + myday; }
        today = year + ‘-‘ + mymonth + ‘-‘ + myday;

        $("#" + endinputid).val(today);

        var enddate = mydate.valueOf();
        enddate = enddate - difference * 24 * 60 * 60 * 1000;
        mydate = new Date(enddate);

        var year = 0;
        var today = "";
        var mymonth = mydate.getMonth() + 1;
        var myday = mydate.getDate();
        var myyear = mydate.getFullYear();
        year = (myyear > 200) ? myyear : 1900 + myyear;
        if (mymonth >= 10) { mymonth = mymonth; } else { mymonth = "0" + mymonth; }
        if (myday >= 10) { myday = myday; } else { myday = "0" + myday; }
        today = year + ‘-‘ + mymonth + ‘-‘ + myday;

        $("#" + startinputid).val(today);


    }
})

///$("#elementid").setDefaultDate();

$.fn.extend({
    setDefaultDate: function (datetype) {
        var day = 0;
        var month = 0;
        var year = 0;
        var today = "";
        mydate = new Date();
        mydate.setTime(mydate.getTime() - 24 * 60 * 60 * 1000);
        mymonth = mydate.getMonth()+1;
        myday = mydate.getDate();
        myyear = mydate.getFullYear();
        year = (myyear > 200) ? myyear : 1900 + myyear;
        if (mymonth >= 10) { mymonth = mymonth; } else { mymonth = "0" + mymonth; }
        if (myday >= 10) { myday = myday; } else { myday = "0" + myday; }
        switch (datetype)
        {
            case "day":
                today = year + ‘-‘ + mymonth + ‘-‘ + myday;
                break;
            case "month":
                today = year + ‘-‘ + mymonth;
                break;
            case "year":
                today = year;
            default:
                break;
        }

        $(this).val(today);
    }
})

 

time

标签:function   today   pre   logs   oda   cas   date()   start   get   

原文地址:http://www.cnblogs.com/rage-the-dream/p/6526787.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!