JavaScript字串和時間處理隨筆

编程小妹發表於2024-03-15
2024-3-15記事
1
// 待處理陣列 2 let arr = []; 3 // 篩選陣列某個欄位(某一列) 4 let jieshus = arr.railways.map(item => item.jieshu); 5 // 獲取當前時間時間戳 6 let now = Date.now(); 7 // 獲取當前時間並轉化成指定格式的日期字串 8 let date = new Date().toLocaleDateString().replaceAll('/', '-'); 9 // 拼接日期+時間,組成當日特定時間 10 let dateTime = date + " " + arr.zhixing_time; 11 // 指定格式"yyyy-MM-dd HH:mm:ss"日期時間轉化成時間戳並計算時間差 12 let timeDelay = Date.parse(new Date(dateTime)) - now;

相關文章