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>

猜你喜欢

转载自www.cnblogs.com/wheatCatcher/p/11015531.html