获取当前时间并转换所需格式

获取当前时间
let datatime = new Date() 
console.log(datatime)
打印结果:Wed Jul 04 2018 11:10:04 GMT+0800 (中国标准时间)

转换时间格式(其中一种)
let datatimes = new Date().getTime()
console.log(datatimes)
打印结果:1530673985063

时间过滤器(这段代码写在main.js里面)
Vue.filter('time', function (value) {
  if (value) {
    let date = new Date(Number(value))
    var Y = date.getFullYear()
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
    var D = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
    var h = date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours();
    var m = date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes();
    var s = date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds();
    return Y + '/' + M +'/' + D + ' ' + h + ':'+ m + ':'+ s
  }
}),在main.js里面定义后,在页面如何引用?例:
  <span class="realCashs">{{orderDetailInfo.postTime | time}}</span>

  

  

  

猜你喜欢

转载自www.cnblogs.com/xingxingzi/p/9262378.html
今日推荐