时间戳判断是否为今天昨天甚至更早时间

2021-05-08  本文已影响0人  前端小猪仔
// 时间戳判断是否为今天昨天甚至更早时间
checkTime(dataTime) {
  let time = new Date(dataTime * 1000)
  let year = time.getFullYear()
  let month = time.getMonth() + 1 
  let date = time.getDate()
  let hour = time.getHours()//时
  let minute = time.getMinutes()//分
  let second = time.getSeconds()//秒
  if (month < 10) { month = '0' + month }
  if (date < 10) { date = '0' + date }
  if (hour < 10) { hour = '0' + hour }
  if (minute < 10) { minute = '0' + minute }
  if (second < 10) { second = '0' + second }
  let data = new Date().toLocaleDateString()
    let dd = Date.parse(data)/1000
    let iday = Math.floor(parseInt(dd-dataTime)/60/60/24);
    if( iday == -1 ){
        return hour + ':' + minute + ':' + second
    }else if(iday == 0){
        return '昨天' + ' ' + hour + ':' + minute + ':' + second
  }else {
    return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second
  }
}
效果图 效果图
上一篇下一篇

猜你喜欢

热点阅读