Home  >  Article  >  Web Front-end  >  Share two ways to get the date of the previous n days in javascript_javascript skills

Share two ways to get the date of the previous n days in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:02:201385browse

Method 1:

Copy code The code is as follows:

var d = new Date( );

d = new Date(d.getFullYear(),d.getMonth(),d.getDate()-n);


Method 2:

Copy code The code is as follows:

var now = new Date( );

now.setTime(now.getTime()-n*24*60*60*1000);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn