时间戳转年月日时分秒 以及 年月日时分秒转时间戳

时间戳转年月日时分秒

export function  timestampToTime (cjsj) {
  //时间戳为10位需*1000,时间戳为13位的话不需乘1000
    var date = new Date(cjsj*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;
}

年月日时分秒转时间戳

export function  getTimeF (timeS) {
  let time =  (new Date(timeS).getTime())/1000; //除1000 是变成秒级的时间戳 不除就是毫秒级
  return time;
}

封装好的,复制即用,不懂得私聊我,有用得话点个赞再走!

你可能感兴趣的:(时间戳转年月日时分秒 以及 年月日时分秒转时间戳)