Does anybody know of an easy way of taking a date (eg Today) and going back X days?(有谁知道约会(例如今天)和回溯X天的简单方法吗?)
So, for example, if I want to calculate the date 5 days before today.(因此,例如,如果我想计算今天前5天的日期。) ask by jonhobbs translate from soDoes anybody know of an easy way of taking a date (eg Today) and going back X days?(有谁知道约会(例如今天)和回溯X天的简单方法吗?)
So, for example, if I want to calculate the date 5 days before today.(因此,例如,如果我想计算今天前5天的日期。) ask by jonhobbs translate from soTry something like this:(尝试这样的事情:)
var d = new Date();
d.setDate(d.getDate()-5);
Note that this modifies the date object and returns the time value of the updated date.(请注意,这将修改日期对象并返回更新日期的时间值。)
var d = new Date(); document.write('Today is: ' + d.toLocaleString()); d.setDate(d.getDate() - 5); document.write('<br>5 days ago was: ' + d.toLocaleString());