输入数字返回多少天前或多少天后

Vue.prototype.$getFutureDate = function (val) {

var now = new Date()

var nowMs = now.getTime()

var beforeMs = nowMs + 1000 * 60 * 60 * 24 * parseInt(val)

var beforeDate = new Date().setTime(beforeMs)

var year = new Date(beforeDate).getFullYear()

var month = new Date(beforeDate).getMonth() + 1

var date = new Date(beforeDate).getDate()

var years = year < 10 ? '0' + year : year

var months = month < 10 ? '0' + month : month

var dates = date < 10 ? '0' + date : date

return years + '-' + months + '-' + dates

}

截图并复制了代码,为方便使用。此方法绑定在了Vue的原型链上。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-26
  • 2021-09-19
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案