本节内容:
判断日期大小
例子:
/**
* 检测两个日期的大小
* by www.jb200.com
*/
function(value, element) {
var productStartTime = document.getElementById("productStartTime").value;
var productEndTime = document.getElementById("productEndTime").value;
var OneMonth = productStartTime.substring(5, productStartTime.lastIndexOf("-"));
var OneDay = productStartTime.substring(productStartTime.length,
productStartTime.lastIndexOf("-") + 1);
var OneYear = productStartTime.substring(0, productStartTime.indexOf("-"));
var TwoMonth = productEndTime.substring(5, productEndTime.lastIndexOf("-"));
var TwoDay = productEndTime.substring(productEndTime.length,
productEndTime.lastIndexOf("-") + 1);
var TwoYear = productEndTime.substring(0, productEndTime.indexOf("-"));
var today = new Date();
var tMonth = today.getMonth() + 1;
var tDay = today.getDate();
var tYear = today.getYear();
if (Date.parse(OneMonth + "/" + OneDay + "/" + OneYear) > Date
.parse(TwoMonth + "/" + TwoDay + "/" + TwoYear)) {
$("#endTime").focus();
return false;
}else{
return true;
}
}
此代码,多用于商品展示程序中,用于判断产品上下架时间,下架时间大于上架时间。