时间戳转换为时间格式(补0)

导出

export function getMyDate(str){  
      var date = new Date(str),  
      MyYear = date.getFullYear(), //年  
      MyMonth = date.getMonth()+1, //月  
      MyDay = date.getDate(),  //日
      h = date.getHours(),//小时
      m = date.getMinutes(),//分钟
      s = date.getSeconds();//秒数
      // 以自己需要的方式拼接
      var MyTime = MyYear +'-'+ getZero(MyMonth) +'-' + getZero(MyDay)+' ' + getZero(h) + ':' +  getZero(m)+ ':' +  getZero(s);//最后拼接时间  
      return MyTime;  
    }

export function getZero(num){  
      // 单数前面加0
      if(parseInt(num) < 10){  
        num = '0'+num;  
      }  
      return num;  
    }

导入

import {  getMyDate } from "@/位置";

使用

getMyDate('1532602549345')//2018-07-26 18:55:49

猜你喜欢

转载自blog.csdn.net/a791226606/article/details/106259716