格式化时间
var date = new Date();
var y = date.getFullYear();
var m = date.getMonth() + 1;
// m = m < 10 ? '0' + m : m;
var d = date.getDate();
// d = d < 10 ? '0' + d : d;
var h = date.getHours();
// h = h < 10 ? '0' + h : h;
var minute = date.getMinutes();
var second = date.getSeconds();
// minute = minute < 10 ? '0' + minute : minute;
// second = second < 10 ? '0' + second : second;
return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
},
将标准时间转成unix时间
var str = dateTime;
str = str.replace(/-/g, '/');
var date = new Date(str);
var humanDate = new Date(
Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds()
)
);
return humanDate.getTime() / 1000 - 8 * 60 * 60;
},
比较两个时间相差天数
datedifference:function(sDate1, sDate2) {//sDate1和sDate2是2006-12-18格
var that=this;
var dateSpan,
tempDate,
iDays;
sDate1 = Date.parse(sDate1);
sDate2 = Date.parse(sDate2);
dateSpan = sDate2 - sDate1;
dateSpan = Math.abs(dateSpan);
iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
return iDays
},
网友评论