moment日期 常用方法

日期拼接 00:00:00 或者 23:59:59

moment(this.beginTime).hours(0).minute(0).seconds(0).format('YYYY-MM-DD HH:mm:ss')

moment(this.endTime).hours(23).minute(59).seconds(59).format('YYYY-MM-DD HH:mm:ss')

日期比较大小 isBefore、isAfter

moment('2022-02-22 22:22:22').isBefore('2022-02-22 22:22:23', null)

moment('2022-02-22 22:22:22').isAfter('2022-02-22 22:22:23', null)

日期范围选择:isBetween函数只接受字符串格式的日期作为参数,所以应该使用format函数将其转换为字符串

moment(moment(new Date()).format('DD-MM-YYYY')).isBetween('2022-02-22', '2022-02-24', null, [])

判断两个日期是否相同

moment(this.date).isSame(moment(item['createTime']).format("YYYY-MM-DD"))
posted @ 2023-02-09 10:04  卡农的忧伤ろ◆  阅读(577)  评论(0)    收藏  举报