微信小程序日期增加时间完成订单失效倒计时(有效果图)

效果图

.wxml

复制代码
<view class="TimeSeond">{{second}}</view>

.js

复制代码
Page({
  data: {
    tiem_one:'',
    second:'',//倒计时
    deadline:'',
  },
  onLoad(){
    this.countdown();
  },
  countdown(){
    let timestamp = Date.parse(new Date()) / 1000;//当前时间戳
    let time = this.addtime('2024-4-19 17:20:00');//当前时间转时间戳
    if(time > timestamp){
      this.deadline = (time - timestamp) * 1000
      this.setData({
        deadline:this.deadline
      })
      this.single()
    }else{
      that.setData({
        second:'00:00'
      })
    }
  },
  addtime(time){
    let date = new Date(time);
    let minutes = date.getMinutes();
    date.setMinutes(minutes+30);//增加三十分钟
    return Date.parse(date) / 1000;
  },
  single(e){
    var that = this
    var time = that.deadline,minutes,seconds;
    that.tiem_one = setInterval(function() {
      time = time - 1000
      minutes = parseInt((time % (1000 * 60 * 60)) / (1000 * 60));
      seconds = parseInt((time % (1000 * 60)) / 1000);
      if (time < 1) {
        that.setData({
          second:'00:00'
        })
        clearInterval(that.tiem_one)
        return false
      }
      minutes = minutes > 9 ? minutes : '0' + minutes
      seconds = seconds > 9 ? seconds : '0' + seconds
      that.setData({
        second:minutes + ':' + seconds
      })
    },1000)
  },
})

遇到问题可以看我主页加我Q,很少看博客,对你有帮助别忘记点赞收藏。

相关推荐
小徐_23331 小时前
Wot UI 2.2.0 发布:Button 新增 subtle,VideoPreview 预览体验继续增强
前端·微信小程序·uni-app
蜗牛前端2 天前
codex 全流程开发上线的高颜值礼簿小程序
前端·微信小程序
爱勇宝6 天前
我想认真做一件小事:让孩子和家长更好地互动
微信小程序·小程序·云开发
唯火锅不可辜负6 天前
避坑指南:iOS 下 scroll-view 嵌套 fixed 布局的“翻车”现场与修复
微信小程序
didiplus6 天前
运维人的随身神器:我把25个常用工具塞进了微信小程序
微信小程序
一份执念7 天前
uni-app 小程序分包限制处理与主包体积优化实战
前端·微信小程序
一份执念7 天前
ECharts 安装与使用完全指南:从全量引入到小程序分包优化
微信小程序·echarts
skiyee8 天前
🔥UniApp 仅需 5 行代码!实现所有页面中控制应用主题变化
前端·微信小程序
Jinkey10 天前
要用户手机号真的是为了打骚扰电话吗?浅谈微信生态会员账号体系与资产合并
后端·微信·微信小程序
用户43242810611411 天前
微信小程序从0到1接入微信支付的完整攻略
微信小程序