博客网站底部页尾添加网站运行时间

makurasho 发布于 2024-07-09 1264 次阅读


预览

本站已运行了

使用方法

在主题页尾信息附加代码footer.php文件适当位置添加下列代码

<div style="color: #39C5BB;">本站已运行了 <span id="daysRunning"></span> 天</div>
<script type="text/javascript">
  const startDate = new Date("2024-07-01"); // 设置起始日期
  const currentDate = new Date();
  const timeDifference = currentDate - startDate;
  const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
  document.getElementById("daysRunning").textContent = days;
</script> 

如主题中页尾信息附加代码分开

页尾信息附加代码分别添加代码的两部分

<div style="color: #39C5BB;">本站已运行了 <span id="daysRunning"></span> 天</div>
<script type="text/javascript">
  // 设置起始日期
  const startDate = new Date("2024-07-01"); // 设置起始日期
  // 获取当前日期
  const currentDate = new Date();
  // 计算日期差异,转换为天数
  const timeDifference = currentDate - startDate;
  const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
  // 更新网页中的天数显示
  document.getElementById("daysRunning").textContent = days;
</script> 

自定义样式

在div标签内使用CSS更改,可自行查看CSS相关知识

此作者没有提供个人介绍
最后更新于 2024-08-02