/**
* 返回时间的天、时、分、秒
* param : 秒
*/
getHhmmss: function (time) {
time = parseInt(time);
if(time <= 0) time = 0;
var s = time >= 60 ? time%60 : time;
var m = parseInt((time>=3600?time%3600:time)/60);
var h = parseInt((time>=86400?time%86400:time)/3600);
var d = parseInt(time/86400);
h = h<10 ? '0'+h : h;
m = m<10 ? '0'+m : m;
s = s<10 ? '0'+s : s;
return {
d: d,
h: h,
m: m,
s: s
}
},
//倒计时
startCountDown:function(time,qg) {
//第一次显示
varhms = this.getHhmmss(time);
qg.hh= hms.h;
qg.mm= hms.m;
qg.ss= hms.s;
qg.day= hms.d;
varinter =setInterval(() => {
time--;
varhms = Vue.utils.getHhmmss(time);
qg.hh= hms.h;
qg.mm= hms.m;
qg.ss= hms.s;
qg.day= hms.d;
if(time <=0) {
clearInterval(inter);
}
},1000);
},
//获取客户端指定时间的date对象
//例子1: getClientDate(10) - 获得今天10:00:00的date
//例子2: getClientDate(9, 57) - 获得今天9:57:00的date
//例子3: getClientDate(9, 57, 30) - 获得今天9:57:30的date
//例子4: getClientDate(24 + 10) - 获得明天10:00:00的date
// 例子5: getClientDate(24 + 9, 57) - 获得明天9:57:00的date
getClientDate:function(hours,minutes,seconds) {
vard =newDate();
//设置小时
d.setHours(hours ||0);
//设置分钟
d.setMinutes(minutes ||0);
//设置秒
d.setSeconds(seconds ||0);
//设置毫秒
d.setMilliseconds(0);
returnd;
},
//根据当前server系统时间将客户端的时间转换成server上的时间
//currentSystime - 当前server系统时间
//clientDate - 客户端的时间
getServerDate: function(currentSystime, clientDate) {
var clientTime = new Date().getTime();
var gap = clientTime - currentSystime;
var serverDate = new Date(clientDate.getTime() - gap);
return serverDate;
},
网友评论