Javascript给网站添加运行天数,比如网站是从今天(2023-08-06)开始上线的;beforeDate = new Date('2023,08,06') ;然后把现在的时间减去网站上线的时间就是网站已经运行的时间戳;最后转换为天数就完成了,每周学习一点JS ~(@^_^@)~
1、HTML
<div> 网站稳定运行<span class="timeLength"></span>天</div>
2、JavaScript
// 需要加载jquery function CountDown(date) { let beforeDate = new Date(date) let nowDate = new Date() let nowTime = nowDate - beforeDate let cdate = parseInt(nowTime / 1000 / 60 / 60 / 24) $('.timeLength').html(cdate) } CountDown('2023,08,01')

