js本身是没有计算日期的函数,所以相对麻烦
示例:
HTML代码:
<tr>
<th>开始时间</th>
<td>
<input type="text" id="TStartDate" style="width:166px" readonly="" name="TStartDate" value="2016-01-12 05:09:20">
</td>
</tr>
<tr>
<th>报名截止时间</th>
<td>
<input class="Wdate" type="text" id="BendDate" οnclick="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width:166px" name="BendDate" value="2016-01-12 05:09:20" οnchange="StartDate()">
</td>
</tr>
js代码:
function StartDate(){
var d = new Date($("#BendDate").val());
d.setDate(d.getDate() + 7);
var year = d.getFullYear();
var month =(d.getMonth()+1).toString();
var day = (d.getDate()).toString();
var hour = (d.getHours()).toString();
var minute = (d.getMinutes()).toString();
var second = (d.getSeconds()).toString();
if (month.length == 1) {
month = "0" + month;
}
if (day.length == 1) {
day = "0" + day;
}
if (hour.length == 1) {
hour = "0" + hour;
}
if (minute.length == 1) {
minute = "0" + minute;
}
if (second.length == 1) {
second = "0" + second;
}
var dateTime = year +"-"+ month +"-"+ day+" "+hour+":"+minute+":"+second;
$("#TStartDate").val(dateTime);
}