10位时间戳转时间

这里用了moment日期处理类库

遇到了小小的坑,

注意,moment(13位)只适合13位的时间戳转时间,10位的时间戳转时间,需要添加moment().unix(10位),就是最下面的方法

  computed: {
    time(){
      return moment(1581767732).format("YYYY.MM.DD hh:mm:ss")
    }//会转成错误的时间1970.01.19 03:22:36,而正确的时间应该是2020-02-15 19:55:32
  },

最后改写了,添加了.unix,就把时间转对了,

10位时间戳的转写方法:

  computed: {
    time() {
      let time = moment
        .unix(1581767732)
        .format("YYYY.MM.DD hh:mm:ss");
      return time;
    }
  },
原文地址:https://www.cnblogs.com/wang715100018066/p/12313681.html