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

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的原型链上。

猜你喜欢

转载自blog.csdn.net/unbreakablec/article/details/86742658