<template>
  <view class="card-time">{{ timeShow }}</view>
</template>

<script>
import dayjs from 'dayjs'
export default {
  props: {
    time: [String, Number]
  },
  computed: {
    timeShow () {
      const res = dayjs(this.time)
      const now = dayjs()
      if (now.format('YYYY年MM月DD日') === res.format('YYYY年MM月DD日')) {
        return res.format('HH:mm:ss')
      }
      if (
        now.subtract(1, 'day').format('YYYY年MM月DD日') ===
        res.format('YYYY年MM月DD日')
      ) {
        return '昨天 ' + res.format('HH:mm:ss')
      }

      return res.format('YYYY年MM月DD日 HH:mm:ss')
    }
  }
}
</script>

<style scoped>
.card-time {
  text-align: center;
  font-size: 28rpx;
  color: #aaaaaa;
  padding: 12rpx 0;
}
</style>
