js日期時間比較

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   os   sp   on   div   

 1 //js日期比較( 要求日期格式:yyyy-mm-dd) 2  3  function DateBiJiao(firstDate, lastDate) { 4     var arr = firstDate.split("-"); 5     var firsttime = new Date(arr[0], arr[1], arr[2]); 6     var firsttimes = firsttime.getTime(); 7  8     var arrs = lastDate.split("-"); 9     var  lasttime = new Date(arrs[0], arrs[1], arrs[2]);10     var  lasttimes =  lasttime.getTime();11 12     if (firsttimes>= lasttimes) {13         return false;14     }15     else16         return true;17 }18 19  20 21 //js時間比較( 要求日期格式:yyyy-mm-dd hh:mi:ss)22 23 function comptime(firstDate,lastDate) {24     var beginTime = firstDate;25     var endTime = lastDate;26     var beginTimes = beginTime.substring(0, 10).split(‘-‘);27     var endTimes = endTime.substring(0, 10).split(‘-‘);28 29     beginTime = beginTimes[1] + ‘-‘ + beginTimes[2] + ‘-‘ + beginTimes[0] + ‘ ‘ + beginTime.substring(10, 19);30     endTime = endTimes[1] + ‘-‘ + endTimes[2] + ‘-‘ + endTimes[0] + ‘ ‘ + endTime.substring(10, 19);31 32     alert(beginTime + "aaa" + endTime);33     alert(Date.parse(endTime));34     alert(Date.parse(beginTime));35     var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;36     if (a < 0) {37         alert("endTime小!");38     } else if (a > 0) {39         alert("endTime大!");40     } else if (a == 0) {41         alert("時間相等!");42     } else {43         return ‘exception‘44     }45 }

 

 

js日期時間比較

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.