时间相加及当前时间

       //日期相加
        function addDate(curDate,day){
            var time = Date.parse(curDate)+24*60*60*1000*day;
            return new Date(time);
        }
        //当前日期
        function currentTime(date)
        {

            var year = date.getFullYear();       //年
            var month = date.getMonth() + 1;     //月
            var day = date.getDate();            //日

            var hh = date.getHours();            //时
            var mm = date.getMinutes();          //分
            var ss = date.getSeconds();          //秒
            var clock = year + "-";

            if(month < 10)
                clock += "0";

            clock += month + "-";

            if(day < 10)
                clock += "0";

            clock += day + " ";

            if(hh < 10)
                clock += "0";

            clock += hh + ":";
            if (mm < 10) clock += '0';
            clock += mm + ":";

            if(ss<10) clock += '0'
            clock += ss;
            return(clock);
        }

posted on 2016-06-20 17:20  会学习的猪  阅读(444)  评论(0编辑  收藏  举报

导航