js将秒转换成几天几小时几分几秒,每秒刷新

			//js将秒转换成几天几小时几分几秒
			function getDuration(second) {
			    var days = Math.floor(second / 86400);
			    var hours = Math.floor((second % 86400) / 3600);
			    var minutes = Math.floor(((second % 86400) % 3600) / 60);
			    var seconds = Math.floor(((second % 86400) % 3600) % 60);
			    var duration = days + "天" + hours + "小时" + minutes + "分" + seconds + "秒";
			    return duration;
			}

		  //每秒刷新(秒杀)
          secondToDate(msd){
				var that = this;
				var interval = setInterval(function () {
					//msd为0或者空时,无秒杀
					if (null != msd && "" != msd && 0 != msd) {
						if (msd > 60 && msd < 60 * 60) {
							that.day = '00';
							that.h = '00';
							var m1 = Math.floor(((msd % 86400) % 3600) / 60).toString();
							var s2 = Math.floor(((msd % 86400) % 3600) % 60).toString();
							
							that.m = m1.length < 2 ? '0' + m1 : m1;
							that.s = s1.length < 2 ? '0' + s1 : s1;
						}else if(msd >= 60 * 60 && msd < 60 * 60 * 24){
							that.day = '00';
							var h1 = Math.floor((msd % 86400) / 3600).toString();
							var m1 = Math.floor(((msd % 86400) % 3600) / 60).toString();
							var s1 = Math.floor(((msd % 86400) % 3600) % 60).toString();
							that.h = h1.length < 2 ? '0' + h1 : h1;
							that.m = m1.length < 2 ? '0' + m1 : m1;
							that.s = s1.length < 2 ? '0' + s1 : s1;
						}else if(msd >= 60 * 60 * 24){
							
							var day1 = Math.floor(msd / 86400).toString();
							var h1 = Math.floor((msd % 86400) / 3600).toString();
							var m1 = Math.floor(((msd % 86400) % 3600) / 60).toString();
							var s1 = Math.floor(((msd % 86400) % 3600) % 60).toString();
							that.day = day1.length < 2 ? '0' + day1 : day1;
							that.h = h1.length < 2 ? '0' + h1 : h1;
							that.m = m1.length < 2 ? '0' + m1 : m1;
							that.s = s1.length < 2 ? '0' + s1 : s1;
							
						}else{
							that.day = '00';
							that.h = '00';
							that.m = '00';
							
							var s1 = Math.floor(((msd % 86400) % 3600) % 60).toString();
							that.s = s1.length < 2 ? '0' + s1 : s1;
						}
						//开启秒杀
						that.seckillState = '1';
						msd--;
					}else{
						//不存在秒杀
						that.seckillState = '0';
						//关闭定时器
						clearInterval(interval);
					}	
				}, 1000)
			},
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值