js中两个字符串时间如何判断大小?
最精确的比较方式应该是,知道字符串对应的时间的格式,然后将字符串转化成date型进行比较。
var time1 = new Date(d1.replace("-", "/").replace("-", "/"));
var time2 = new Date(d2.replace("-", "/").replace("-", "/"));
if(time1 > time2)alert("time1 大于 time2");
date1=new Date('12-11-2000');
date2=new Date('12-12-2000');
alert("日期差值为:"+(date2-date1));
var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ("-"));
var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ("-")+1);
var OneYear = DateOne.substring(0,DateOne.indexOf ("-"));
var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ("-"));
var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ("-")+1);
var TwoYear = DateTwo.substring(0,DateTwo.indexOf ("-"));
(Date.parse(OneMonth+"/"+OneDay+"/"+OneYear) >
Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear))