var dateStr = 2023-01-27 var postDate = new Date(dateStr); var today = new Date(); var daysDiff = Math.ceil((today - postDate) / (1000 * 60 * 60 * 24)); // 计算帖子发布时间和当前时间的天数差 var days = 2023-01-27 输出 console.log 测试各项参数当前值
console.log(dateStr); // "2023-01-27" console.log(postDate); // "Sat Jan 27 2023 00:00:00 GMT+0000 (Coordinated Universal Time)" console.log(today); // current date and time console.log(daysDiff); // number of days between postDate and today console.log(days); // "2023-01-27"
原文地址: https://www.cveoy.top/t/topic/By4 著作权归作者所有。请勿转载和采集!