JavaScript 比較時間大小

來源:互聯網
上載者:User

js靜態函數Date.prase() 參數有很嚴格的要求。否則就會轉化失敗。

例如: Date.parse( "2000-01-01" ) IE and Mozilla瀏覽器: "NaN"。那麼我們一般在Web頁面上顯示的時 間   就不能直接轉換。需要做處理。

可以直接轉換的格式"01/01/2000","2000/01/01"

//定義Regex,因為jS對只能替換一個

//轉換為 "2000/01/01"

var regS = new RegExp("-","gi");

var date1=document.getElementById("begindate");

var date2=document.getElementById("enddate");

date1=date1.replace(regS,"/");

 

date2=date2.replace(regS,"/");

var bd =new Date(Date.parse(date1));

var ed =new Date(Date.parse(date2));

bd,ed是時間對象,可以直接比較大小了

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.