moment——日期格式化經常使用示例

<template>
  <div id="app" style="text-align: center;">
    <h1>{{ msg | format}}</h1>
  </div>
</template>

<script>
import moment from 'moment'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')
export default {
  name: 'app',
  data () {
    return {
      msg: new Date
    }
  },
  filters:{
    format(val){
      // return moment(val).calendar() //默認爲英文、引入後設置格式
      // return moment(val).format('YYYY年MM月DD日') //自定義方案1,簡寫:LL 或 ll
      // return moment(val).format('YYYY-MM-DD HH:mm:ss') //大寫HH爲24小時制,小寫dd爲星期
      // return moment(val).format('hh:mm:ss a') //12小時制
      // return moment(val).format('YYYYMMDDHHmmss') //純數字日期
      // return moment(val).subtract(1, "days").format("YYYY-MM-DD HH:mm:ss") //1天前(add:後):weeks、months、years、hours、minutes、seconds
      // return moment(val).format("LLLL") //全中文日期
      // return moment(val).format("dddd") //獲取星期
      // return moment(val).valueOf() //完整的時間戳
      // return moment(val).format('X') //秒結尾
      // return moment(val).format('x') //毫秒結尾
      return moment(val).format('LLLL')
    }
  }
}
</script>
相關文章
相關標籤/搜索