码迷,mamicode.com
首页 > 其他好文 > 详细

时间戳转换日期格式 - Vue

时间:2020-12-09 12:17:00      阅读:4      评论:0      收藏:0      [点我收藏+]

标签:span   date()   时间格式   second   接口   get   style   ==   vue   

日常开发中经常会遇到时间相关的问题,服务端返回的数据都是以时间戳的方式,那么需要将其处理转化为对应的时间格式,具体方式如value为接口返回的时间戳

if (value == null) {
                    return ‘‘;
                } else {
                    let date = new Date(value);
                    let y = date.getFullYear();//
                    let MM = date.getMonth() + 1;//
                    MM = MM < 10 ? (‘0‘ + MM) : MM;
                    let d = date.getDate();//
                    d = d < 10 ? (‘0‘ + d) : d;
                    let h = date.getHours();//
                    h = h < 10 ? (‘0‘ + h) : h;
                    let m = date.getMinutes();//
                    m = m < 10 ? (‘0‘ + m) : m;
                    let s = date.getSeconds();//
                    s = s < 10 ? (‘0‘ + s) : s;
                    var timer y + ‘-‘ + MM + ‘-‘ + d + ‘ ‘ + h + ‘:‘ + m + ‘:‘ + s;
                    this.timer = timer //转换结果为 2019-05-15 15:30:24 
                }

 

时间戳转换日期格式 - Vue

标签:span   date()   时间格式   second   接口   get   style   ==   vue   

原文地址:https://www.cnblogs.com/wangkunlong/p/14088469.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!