您的位置:首页 > Web前端 > JavaScript

Js 日期加减天数

2014-02-16 11:09 281 查看
<SCRIPT language="javascript">
function addDate(dd,dadd){
var a = new Date(dd)
a = a.valueOf()
a = a + dadd * 24 * 60 * 60 * 1000
a = new Date(a)
return a;
}

//抓取现在日期

var now = new Date("2008/03/01");
var years = now.getYear()+1;
var months = now.getMonth()+1;
var days = now.getDate();
var hours = now.getHours();

//抓取前一天日期

NextNow = addDate(months+"/"+days+"/"+years,-1);
years = NextNow.getYear();
months = NextNow.getMonth()+1;
days = NextNow.getDate();

alert("加一年减一天的日期:"+years+"年"+months+"月"+days+"日");

</SCRIPT>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: