|
阅读:6630回复:1
时间的格式 和转换 vue中使用moment.js
当前时间
var d = new Date(); //里面不填东西的话是输出当前时间 console.log(d); // 输出:Wed Feb 13 2019 16:49:31 GMT+0800 (中国标准时间) var d = new Date().getTime() // 后面加 getTime()就是把当前的(中国标准时间)转成时间戳输出 console.log(d) // 输出是当前时间戳 1574686929197; var d = new Date(1574686929197) console.log(d) //是把你的时间戳转成(中国标准时间) Mon Nov 25 2019 21:02:09 GMT+0800 时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。 function timestampToTime(timestamp) {
var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 //上面这句话是将时间戳转换成(中国标准时间)这种格式才能使用对应的方法和属性 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; } timestampToTime(1529111288); vue中使用moment.js 1.安装 2. 在main.js中导入并且做一定配置
filters:{
datefilter:function(value){
return moment(value).format('MMMM Do YYYY, h:mm:ss a');
}
},[969188664于2019-11-27 23:57编辑了帖子]
|
|