日期:2014-05-16 浏览次数:20361 次
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script type="text/javascript"> //date string format: MM/DD/YYY function compareDate(dstr1,dstr2){ var d1 = new Date(); d1.setFullYear(Number(dstr1.substring(6)),Number(dstr1.substring(0,2))-1,Number(dstr1.substring(3,5))); var d2 = new Date(); d2.setFullYear(Number(dstr2.substring(6)),Number(dstr2.substring(0,2))-1,Number(dstr2.substring(3,5))); if(Math.floor(d1.getTime()/(3600*24*1000)) >= Math.floor(d2.getTime()/(3600*24*1000))){ alert("d1>=d2"); }else{ alert("d1<d2"); } } compareDate("07/18/2011","07/15/2011"); </script> </head> <body> </body> </html>
?
??? 在javascript的Date对象里,没有对时区的设置,如果要比较两个不同时区的时间,加减对应的时差是我想到的唯一办法。