moment 日常使用

//获取去年今天
this.$moment().subtract(1,'year').format("YYYY-MM-DD")
//指定时间月份 第一天
this.$moment(value[0]).startOf('month').format("YYYY-MM-DD")
this.$moment(value[0]).format("YYYY-MM-01")

//获取前后 一日 一周 一月 一年
const type = 'left'
const result = this.$moment(this.currentDate).subtract(type == 'left' ? 1 : -1, 'day').format(this.valueFormat)
const result = this.$moment(this.currentDate).subtract(type == 'left' ? 1 : -1, 'week').format(this.valueFormat)
const result = this.$moment(this.currentDate).subtract(type == 'left' ? 1 : -1, 'month').format(this.valueFormat)
const result = this.$moment(this.currentDate).subtract(type == 'left' ? 1 : -1, 'year').format(this.valueFormat

posted on 2022-07-07 21:55  文仲玉  阅读(57)  评论(0编辑  收藏  举报