javascript几个月前的时间

function agomonth(x) {
  var date = new Date();
  date.setMonth(date.getMonth()-x);
  return date.getFullYear()+'-'+(date.getMonth()+1)+'-01'
}

调用月份处理函数:时间设置为月初

agomonth(0)

"2017-1-01"
agomonth(1)
"2016-12-01"

posted @ 2017-01-11 14:10  绵山  阅读(228)  评论(0编辑  收藏  举报