这是用原生的js来获取3天前时间的方法:
var threeDaysAgo = new Date();
threeDaysAgo.setDate(threeDaysAgo.getDate()-3);
var formatDay = threeDaysAgo.getFullYear()+"-"+(threeDaysAgo.getMonth()+1)+'-'+threeDaysAgo.getDate();
所要的时间格式,可以如此设置。
因为getMonth()的范围是0-11 ,所以最后要加1
本文介绍了一种使用原生JavaScript获取三天前日期的方法,并展示了如何格式化日期。通过简单的代码实现,帮助开发者快速掌握日期处理技巧。
2251

被折叠的 条评论
为什么被折叠?



