日期:2014-05-16 浏览次数:20377 次
var date = new Date(); //日期对象 var now = ""; now = date.getFullYear()+"-"; now = now + (date.getMonth()+1)+"-"; now = now + date.getDate(); alert(now);
//日期增加函数 function dateAdd(s,dtDate) { var dtTmp = new Date(dtDate); if (isNaN(dtTmp)) dtTmp = new Date(); var m=dtTmp.getMonth(); if(s=="w"){ dtTmp=new Date(Date.parse(dtTmp) + 86400000 * 7); }else{ dtTmp=new Date(dtTmp.getFullYear(),dtTmp.getMonth() + 1, dtTmp.getDate()); if(dtTmp.getMonth()>m+1){ dtTmp=new Date(dtTmp.getFullYear(),dtTmp.getMonth(), 0); } } return dtTmp.getFullYear()+"-"+(dtTmp.getMonth() +1)+"-"+dtTmp.getDate() } alert(dateAdd("w",new Date(2012,10-1,29))); //得出 2012-11-5 alert(dateAdd("m",new Date(2012,10-1,31))); //得出 2012-11-30 //注意传入的月份比实现小1【0-11】