首页 >web前端 >js教程 >如何使用Javascript获取距今n天前的日期_javascript技巧

如何使用Javascript获取距今n天前的日期_javascript技巧

WBOY
WBOY原创
2016-05-16 17:29:521478浏览
复制代码 代码如下:

 function Test(day) {
                var today = new Date();
                var beforMilliseconds = today.getTime() - 1000 * 3600 * 24 * day;
                var beforday = new Date();
                beforday.setTime(beforMilliseconds);
                var strYear = beforday.getFullYear();
                var strDay = beforday.getDate();
                var strMonth = beforday.getMonth() + 1;
                if (strMonth                     strMonth = "0" + strMonth;
                }
                var strYesterday = strYear + "-" + strMonth + "-" + strDay;
                alert(strYesterday);
            }
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn