有的时候难免会有要求前或者后几天日期的需求,写在后端又比较麻烦,所以就请我的前端同事帮我写了一个小功能,可以获得当前及前一段时间或者后一段时间的小模块,在这里跟大家分享一下。下面是代码:
function getBeforeDate(n){//n为你要传入的参数,当前为0,前一天为-1,后一天为1 var date = new Date()
; var year,month,day ; date.setDate(date.getDate()+n); year =
date.getFullYear(); month = date.getMonth()+1; day = date.getDate() ; s = year
+ '-' + ( month < 10 ? ( '0' + month ) : month ) + '-' + ( day < 10 ? ( '0' +
day ) : day) ; return s ; }
下面是测试效果:



 

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信