js比较时间早晚
function compareTime(beginTime, endTime) {
var beginTimes = beginTime.replace(/-/g, "/");
var endTimes = endTime.replace(/-/g, "/");
console.log("beginTimes =" + beginTimes);
console.log("endTimes =" + endTimes);
var a = (Date.parse(endTimes) - Date.parse(beginTimes)) / 3600 / 1000;
if (a < 0) {
console.log("endTime小!");
return false;
} else if (a > 0) {
console.log("endTime大!");
return true;
} else if (a == 0) {
console.log("相等!");
return false;
}
}
js根据字段去重
function arrayUnique2(arr, name) {
var hash = {};
return arr.reduce(function (item, next) {
hash[next[name]] ? '' : hash[next[name]] = true && item.push(next);
return item;
}, []);
}
yyyy-mm-dd 转换年月日
endTime(val) {
if(val==null){
return '暂无时间'
}
var endTime;
var index=val.lastIndexOf("T");
endTime=val.substring(0,index);
var date = endTime;
var nDate = new Date(date);
var year = nDate.getFullYear();
var month = nDate.getMonth() + 1;
var day = nDate.getDate();
endTime=year + "年" + month + "月" + day+"日"
// alert();
return endTime;
},