var d = new Date();
d.setDate(d.getDate() + 5); //假設要取五天後的日期
var yyyy = d.getFullYear().toString();
var mm = (d.getMonth() + 1).toString(); //getMonth() is zero-based
var dd = d.getDate().toString();
var str_date = yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]);
alert(str_date);
備註:如果要取上個月的日期,請改成 d.setMonth(d.getMonth() - 1);
No comments:
Post a Comment