倒计时:xx天xx时xx分xx秒

1.时间转换,时间戳转换成时间xx天xx时xx分xx秒;

var dayeach = 60 * 60 * 24;
var days = parseInt(s / dayeach);
var give1 = s - days * dayeach;
var houreach = 60 * 60;
var hours = parseInt(give1 / houreach);
var give2 = give1 - hours * houreach;
var minutes = parseInt(give2 / 60);
var seconds = give2 - minutes * 60;
that.times = that.rep(days) + " 天 " + that.rep(hours) + " 小时 " + that.rep(minutes) +" 分钟 " + that.rep(seconds) + '秒';

2.写倒计时

//倒计时
countDown() {
	let that = this
	var s = that.time;
	setInterval(() => {
		s--;
		var dayeach = 60 * 60 * 24;
		var days = parseInt(s / dayeach);
		var give1 = s - days * dayeach;
		var houreach = 60 * 60;
		var hours = parseInt(give1 / houreach);
		var give2 = give1 - hours * houreach;
		var minutes = parseInt(give2 / 60);
		var seconds = give2 - minutes * 60;
		that.times = that.rep(days) + " 天 " +that.rep(hours) + " 小时 " + that.rep(minutes) +
			" 分钟 " + that.rep(seconds) + '秒';
	}, 1000);
	if (s <= 0) {
		that.times = '大赛已结束';
	}
},

不够十位数数字前添加零,例如:07天

rep(str) {
	if (str < 10) {
		return '0' + str
	} else {
		return str
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值