请问pbootcms中可用的自动计算日期的代码
<script> window.onload = function() { function calculateDays() { var currentDate = new Date('2020-02-21'); var nextYearDate = new Date(currentDate.getFullYear() + 5, currentDate.getMonth(), currentDate.getDate()); document.getElementById('qunian').innerHTML = '' + nextYearDate.toLocaleDateString(); } calculateDays(); }; </script> 上述代码表示:在日期:2020-02-21的基础上加上 5年,以得到未来五年后的日期;2020-02-21可以替换为其他时间标签或日期! 结果调用标签:<span id="qunian"></span> <script> window.onload = function() { function otherFunction() { var startDate = new Date("2020-02-21"); var endDate = new Date("2023-07-25"); // 计算日期间的毫秒数差值 var timeDiff = endDate.getTime() – startDate.getTime(); // 将毫秒数差值转换为天数 var days = Math.ceil(timeDiff / (1000 * 3600 * 24)); document.getElementById("tianshu").innerHTML = "" + days; } otherFunction(); }; </script> 上面代码表示计算两个日期之间的天数,调用代码:<span id="tianshu"></span>
更新时间:2025-04-10 23:46:43
上一篇:请问PbootCMS 网站在阿里云虚拟主机上验证码不显示原因
下一篇:请问PbootCMS授权码是否可以用于不同域名的子域名?是否可以用于不同域名的子目录?
转载请注明原文链接:https://www.muzicopy.com/suibi/3523.html