//比較日期大小
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);
}