美文网首页
时间常用处理

时间常用处理

作者: 懒懒猫 | 来源:发表于2022-02-28 15:19 被阅读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)

相关文章

网友评论

      本文标题:时间常用处理

      本文链接:https://www.haomeiwen.com/subject/exnjlrtx.html