现在的位置: 首页 > 综合 > 正文

js转换日期 代码实例

2012年07月02日 ⁄ 综合 ⁄ 共 1118字 ⁄ 字号 评论关闭
function changeDeadline() {
        var days = parseInt(document.getElementById("<%=hd_days.ClientID %>").value);
        var datetemp = document.getElementById("<%=tb_cir.ClientID %>").value
        var CurrentDate = datetemp.replace("-","/");

        var tarDate = new Date(CurrentDate);
        var deadline = document.getElementById("<%=tb_deadline.ClientID %>").value;
        var temp = 0;
        for (i = 1; i <= days; i++) {
            tarDate = new Date((tarDate).valueOf() + 1 * 24 * 60 * 60 * 1000);
            //alert();
            if ((tarDate.getDay() == 0) || (tarDate.getDay() == 6)) {
                days++;
            }
        }

        document.getElementById("<%=tb_deadline.ClientID %>").value = tarDate.getFullYear() + "-" + (tarDate.getMonth() + 1) + "-" + tarDate.getDate();
        document.getElementById("<%=hd_deadline.ClientID %>").value = tarDate.getFullYear() + "-" + (tarDate.getMonth() + 1) + "-" + tarDate.getDate();
    }

    // 将日期类型转换成字符串型格式yyyy-MM-dd  

    function ChangeDateToString(DateIn) {
        var Year = 0;
        var Month = 0;
        var Day = 0;

        var CurrentDate = "";

        //初始化时间
        Year = DateIn.getYear();
        Month = DateIn.getMonth() + 1;
        Day = DateIn.getDate();


        CurrentDate = Year + "-";
        if (Month >= 10) {
            CurrentDate = CurrentDate + Month + "-";
        }
        else {
            CurrentDate = CurrentDate + "0" + Month + "-";
        }
        if (Day >= 10) {
            CurrentDate = CurrentDate + Day;
        }
        else {
            CurrentDate = CurrentDate + "0" + Day;
        }


        return CurrentDate;
    }

 

抱歉!评论已关闭.