//比较日期大小
function compareDate(checkStartDate, checkEndDate) {
var arys1= new Array();
var arys2= new Array();
if(checkStartDate != null && checkEndDate != null) {
arys1=checkStartDate.split('-');
var sdate=new Date(arys1[0],parseInt(arys1[1]-1),arys1[2]);
arys2=checkEndDate.split('-');
var edate=new Date(arys2[0],parseInt(arys2[1]-1),arys2[2]);
if(sdate < edate) {
return true;
} else {
layer.alert("证件有效期起应小于证件有效期止");
return false;
}
}
}
// 日期格式化 时间戳
function timestampToTime(timestamp) {
var date = new Date(timestamp);
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
return Y + M + D + h + m + s;
}
//时间转换-毫秒转时分秒
function MillisecondToDate(msd) {
var times = parseFloat(msd) / 1000;
if (null != times && "" != times) {
times = parseInt(times / 3600.0) + "时" + parseInt((parseFloat(times / 3600.0) -
parseInt(times / 3600.0)) * 60) + "分" +
parseInt((parseFloat((parseFloat(times / 3600.0) - parseInt(times / 3600.0)) * 60) -
parseInt((parseFloat(times / 3600.0) - parseInt(times / 3600.0)) * 60)) * 60) + "秒";
}
console.log(times)
return times;
}
// 补零
fixZero(num,length){
var str=""+num;
var len=str.length;
var s="";
for(var i=length;i-->len;){
s+="0";
}
return s+str;
}
倒计时
countTime() {
let date = new Date();
let now = date.getTime();
let start = that.objectArray.createTime;
// 计算开始时间
let startDate = new Date(start.replace(/-/g, '/'));
//计算订单截止时间
let endDate = startDate.getTime() + 1800000;//时间差
// 下单时间已超出30分钟
let lifetime = endDate - now;
if (lifetime <= 0) {
that.isActualStock = true;
that.countdownArr.countdown = '00:00:00';
return false;
}//未超出
that.countdownArr.lifetime = that.countdownArr.lifetime - 1000;
//定义变量 d,h,m,s保存倒计时的时间
if (that.countdownArr.lifetime >= 0) {
let h = Math.floor(that.countdownArr.lifetime / 1000 / 60 / 60 % 24);
let m = Math.floor(that.countdownArr.lifetime / 1000 / 60 % 60);
let s = Math.floor(that.countdownArr.lifetime / 1000 % 60);
that.time.h = h < 10 ? '0' + h : h;
that.time.m = m < 10 ? '0' + m : m;
that.time.s = s < 10 ? '0' + s : s;
}
//递归每秒调用countTime方法,显示动态时间效果
this.countdownArr.countdown = that.time.h + ':' + that.time.m + ':' + that.time.s
setTimeout(that.countTime, 1000);
}