close
取得一週前的日期
You can modify a date using setDate
. It automatically corrects for shifting to new months/years etc.
var oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
And then go ahead to render the date to a string in any matter you prefer.
--
取得一個月前的日期
function getOneMonthAgoDate()
{
var d = new Date();
d.setMonth(d.getMonth() - 1);
var month = d.getMonth()+1;
var day = d.getDate();
var output = d.getFullYear() + '-' +
(month<10 ? '0' : '') + month + '-' +
(day<10 ? '0' : '') + day;
return output;
}
--
參考
https://stackoverflow.com/questions/8489500/how-do-i-subtract-one-week-from-this-date-in-jquery
全站熱搜
留言列表