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

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 dizzy03 的頭像
    dizzy03

    碎碎念

    dizzy03 發表在 痞客邦 留言(0) 人氣()