今天做一个小程序,后台拿到的数据,时间是时间戳的形式,要把她转换为普通日期格式,一分钟百度出来~
Vue.filter("formatDate",function(time: any){
if (time == null) {
return '';
} else {
let date = new Date(time);
let y = date.getFullYear();// 年
let MM:any = date.getMonth() + 1;// 月
MM = MM < 10 ? ('0' + MM) : MM;
let d:any = date.getDate();// 日
d = d < 10 ? ('0' + d) : d;
return y + '-' + MM + '-' + d ;
}
因为我是用vue写的,所以我写了一个全局过滤器
然后就可以直接使用了
<view class="left">{{item.ct | formatDate}}</view>