javascript日期操作

javascript获取给定日期N天后的日期:

<script language="javascript">
function showDate(initDate,num)
{
 initDate =  initDate.replace('-','/');
 var dateObj = new Date(initDate);

 dateObj.setDate(dateObj.getDate()+num);
 var endDay = dateObj.getDate();
 var endMonth = dateObj.getMonth() + 1;
 var endYear = dateObj.getYear();
 var endDate = endYear + '-' + endMonth + '-' + endDay;
 alert(endDate);
}
</script>

posted on 2012-03-03 15:10  沉淀的心  阅读(244)  评论(0编辑  收藏  举报

导航