时间戳转时间


function formatTime(obj){
    obj = obj.toString().length ==10 ?parseInt(obj) *1000 : obj;
    let date =new Date(obj);
    let _year =date.getFullYear(),
    _month = (date.getMonth() +1) >9 ? (date.getMonth() +1) :'0' + (date.getMonth() +1),
    _date =date.getDate() >9 ?date.getDate() :'0' +date.getDate(),
    _hour =date.getHours()>9 ?date.getHours() :'0' +date.getHours(),
    _minute =date.getMinutes()>9 ?date.getMinutes() :'0' +date.getMinutes(),
    _second =date.getSeconds()>9 ?date.getSeconds() :'0' +date.getSeconds()
    return _year +'-' +_month +'-' +_date +' ' +_hour +':' +_minute +':' +_second
}
formatTime('1533801174','yyyy-MM-dd');

你可能感兴趣的:(时间戳转时间)