js/ts 計算兩段時間相差多少天


 

let n_date = new Date();
let l_str: string[] = '2020/1/1'.split("/");           //過去的時間
let n_str: string[] = n_date.toLocaleDateString().split("/"); //當前的時間-- 格式:2020/12/31 
  let oDate1 = new Date(((l_str[1] + '-' + l_str[2] + '-' + l_str[0]).replace(/-/g, "/"))); let oDate2 = new Date(((n_str[1] + '-' + n_str[2] + '-' + n_str[0]).replace(/-/g, "/"))); let iDays = Math.floor(Math.abs(oDate1.getTime() - oDate2.getTime()) / 1000 / 60 / 60 / 24);

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM