获取当前时间并转换所需格式
Posted xingxingzi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取当前时间并转换所需格式相关的知识,希望对你有一定的参考价值。
获取当前时间 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>
以上是关于获取当前时间并转换所需格式的主要内容,如果未能解决你的问题,请参考以下文章