在引用了Moment.js 后

formatDate() {
  return function (val) {
    let that = this;
    this.$moment.lang("zh", {
      calendar: {
        lastDay: "[昨天] HH:mm:ss",
        lastWeek: "MM月DD日 HH:mm:ss",
        nextDay: "[明天] HH:mm:ss",
        nextWeek: "MM月DD日 HH:mm:ss",
        sameDay: "[今天] HH:mm",
        sameElse: function (now) {
          if (that.isThisYear(now, val)) {
            return "MM月DD日 HH:mm:ss";
          } else {
            return "YYYY年MM月DD日 HH:mm:ss";
          }
        }

      },
    });

    return this.$moment(val).calendar();
  };
},
//判断时间是否是今年
isThisYear(now, val) {
      if (val) {
        return this.$moment().year() === new Date(val).getFullYear()
      }
},
 
 
使用方法:formatDate(time)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-12-06
  • 2022-12-23
  • 2022-02-09
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-09-04
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案