/**
* 日期加减
* @param dayNum 可为负数,为负数时,是减去天数。
* @returns {String}
*/
function addDate(dayNum){
var now = new Date();
var years = now.getFullYear();
var months = now.getMonth()+1;
var days = now.getDate();
var hours = now.getHours();
var a = new Date(months+"/"+days+"/"+years);
a = a.valueOf();
a = a + (dayNum) * 24 * 60 * 60 * 1000;
a = new Date(a);
var newDate = a;
years = newDate.getFullYear();
months = newDate.getMonth()+1;
days = newDate.getDate();
var resultDate=years+"-"+months+"-"+days;
alert("结果日期:"+resultDate);
return resultDate;
}
js 日期加减
最新推荐文章于 2024-08-27 15:36:53 发布