Moment.js時間

來源:互聯網
上載者:User

標籤:time()   months   ref   log   時間差   time   art   moment   star   

                    http://momentjs.cn/ 官網      format("YYYY-MM-DD")   "-"可以換   年/月/日或?/?/? 
  1. console.log(moment().format("YYYY-MM-DD HH:mm:ss")); //目前時間
  2. console.log(moment().subtract(10, "days").format("YYYY-MM-DD")); //目前時間的前10天時間 
  3. console.log(moment().subtract(1, "years").format("YYYY-MM-DD")); //目前時間的前1年時間 
  4. console.log(moment().subtract(3, "months").format("YYYY-MM-DD")); //目前時間的前3個月時間 
  5. console.log(moment().subtract(1, "weeks").format("YYYY-MM-DD")); //目前時間的前一個星期時間 
  6. 兩個時間差var date1 = new Date(‘2013/04/02 18:00‘)   var date2 = new Date(‘2013/04/02 19:22:21‘) var s1 = date1.getTime(),s2 = date2.getTime();
  var total = (s2 - s1)/1000;   var day = parseInt(total / (24*60*60));//計算整數天數  var afterDay = total - day*24*60*60;//取得算出天數後剩餘的秒數  var hour = parseInt(afterDay/(60*60));//計算整數小時數  var afterHour = total - day*24*60*60 - hour*60*60;//取得算出小時數後剩餘的秒數  var min = parseInt(afterHour/60);//計算整數分  var afterMin = total - day*24*60*60 - hour*60*60 - min*60;//取得算出分後剩餘的秒數

Moment.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.