JavaScript 日期比較

2009年9月16日 星期三

if ((Date.parse("9/17/2009")).valueOf() > (new Date()).valueOf())
{
    alert('今天比 2009/9/17還小');
}
else
{
    alert('今天比 2007/9/17還大');
}
    var ckDate = "2015/10/28 18:10:35";
    var htoday = "2015/10/28 18:10:34";
    var today = new Date(htoday);
    var checkDate = new Date(ckDate)
    
    if(checkDate.getTime() > today.getTime())
      {
          console.log('yes');
      }
    else
      {
          console.log('no');
      }

參考:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
https://msdn.microsoft.com/zh-tw/library/ee532932(v=vs.94).aspx

0 意見: