时间常用处理

2022-02-28  本文已影响0人  懒懒猫

时间戳转化为日期

const format = (shijianchuo) => {
    var date = new Date(shijianchuo);
  
    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;
  }

日期转化为时间戳

const formatTime = (data) => {
    var time = new Date(data);
    return time.getTime();
  }

日期截取年月日
time.slice(0, 11)

上一篇 下一篇

猜你喜欢

热点阅读