Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
399 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try 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());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...