[b]js对于2011-10-10 00:10:26时间类型格式进行比较:[/b]
[b]jqeury对于2010/01/20时间类型格式的比较:[/b]
<script type="text/javascript">
function compareTo(){
var beginTime = "2009-09-21 00:00:02";
var endTime = "2009-09-21 00:00:01";
var beginTimes = beginTime.substring(0,10).split('-');
var endTimes = endTime.substring(0,10).split('-');
beginTime = beginTimes[1]+'-'+beginTimes[2]+'-'+beginTimes[0]+' '+beginTime.substring(10,19);
endTime = endTimes[1]+'-'+endTimes[2]+'-'+endTimes[0]+' '+endTime.substring(10,19);
alert(beginTime);
alert(endTime);
var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
alert(a);
if(a<0){
alert("endTime小!");
}else if (a>0){
alert("endTime大!");
}else if (a==0){
alert("时间相等!");
}
}
</script>
[b]jqeury对于2010/01/20时间类型格式的比较:[/b]
<script type="text/javascript">
$(function()
{
$("#btn").click(function()
{
var beg=$("#begTime").val();
var end=$("#endTime").val();
var date1 = new Date(Date.parse(beg));
var date2 = new Date(Date.parse(end));
if (date1.getTime() > date2.getTime()) {
alert("结束时间不得小于开始时间。");
return false;
}
});
});
</script>