js比較日期

wl1121發表於2009-05-30

 

  if (Date.parse($("#startdate").val().replace("-", "/")) > Date.parse($("#enddate").val().replace("-", "/"))) {
                    alert("起始日期要小於或等於截至日期");
                    return;
                }

 注意日期格式轉化。

 

var myDate=new Date();
myDate.setFullYear(2008,8,9);

var today = new Date();

if (myDate>today)
{
alert("Today is before 9th August 2008");
}
else
{
alert("Today is after 9th August 2008");
}

 

相關文章