评论

获取当前系统时间戳

获取当前系统时间戳


获取当前的时间:然后处理一系列逻辑


getHours(){
  let time = (new Date()).getTime(); // 获取当前时间戳
  console.log('time=='+time);
  let timeDate = this.orderInfo.pay_time;
  //let Time = new Date(timeDate);
  let Time = new Date(timeDate.replace(/-/g, '/'))
  let timestemp = Time.getTime(); //得到时间戳
  console.log('timestemp====',timestemp)

  let timeDiff = time - timestemp
  console.log('timeDiff==',time - timestemp);
  const hours = parseInt(timeDiff/3600000 ) // 当前时间和服务器时间的差值,计算出小时数
  console.log('hours==',hours);
  this.hours = hours
},
点赞 1
收藏
评论

1 个评论

  • 拾忆
    拾忆
    2022-07-20
    let timeDate = this.orderInfo.pay_time;
    let Time = new Date(timeDate.replace(/-/g, '/'))
    let timestemp = Time.getTime(); //得到时间戳
    
    可以换成
    
    let timestemp = new Date(this.orderInfo.pay_time).valueOf()
    
    2022-07-20
    赞同 2
    回复 1
登录 后发表内容