標籤:time() months ref log 時間差 time art moment star
http://momentjs.cn/ 官網 format("YYYY-MM-DD") "-"可以換 年/月/日或?/?/?
- console.log(moment().format("YYYY-MM-DD HH:mm:ss")); //目前時間
- console.log(moment().subtract(10, "days").format("YYYY-MM-DD")); //目前時間的前10天時間
- console.log(moment().subtract(1, "years").format("YYYY-MM-DD")); //目前時間的前1年時間
- console.log(moment().subtract(3, "months").format("YYYY-MM-DD")); //目前時間的前3個月時間
- console.log(moment().subtract(1, "weeks").format("YYYY-MM-DD")); //目前時間的前一個星期時間
- 兩個時間差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時間