//时间比较(yyyy-mm-dd) function comparedate(startdate, enddate) { var arrstart = startdate.split("-"); var starttime = new date(arrstart[0], arrstart[1], arrstart[2]); var starttimes = starttime.gettime(); var arrend = enddate.split("-"); var endtime = new date(arrend[0], arrend[1], arrend[2]); var endtimes = endtime.gettime(); if (endtimes<starttimes) { alert("结束时间不能小于开始时间"); return false; } return true; } //时间比较(yyyy-mm-dd hh:mm:ss) function comparetime(starttime,endtime) { var starttimes = starttime.substring(0, 10).split('-'); var endtimes = endtime.substring(0, 10).split('-'); starttime = starttimes[1] + '-' + starttimes[2] + '-' + starttimes[0] + ' ' + starttime.substring(10, 19); endtime = endtimes[1] + '-' + endtimes[2] + '-' + endtimes[0] + ' ' + endtime.substring(10, 19); var thisresult = (date.parse(endtime) - date.parse(starttime)) / 3600 / 1000; if (thisresult < 0) { alert("endtime小于tarttime!"); } else if (thisresult > 0) { alert("endtime大于tarttime!"); } else if (thisresult == 0) { alert("endtime等于tarttime!"); } else { return '异常'; } }
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
怎么隐藏js代码
使用js经验小结
!=、== 、!==、===使用总结
以上就是js中时间单位比较的方法的详细内容。
