帝国cms时间显示几年前、几天前、几小时前等等的js代码

此代码首页可用
使用说明:

1. 引入js文件:

<script src="https://cdn.bootcss.com/timeago.js/3.0.2/timeago.js"></script>

建议换成你本地的 js 地址

2. 获取时间:

使用灵动标签的话用 来获取

3. 转换成几年(天、小时等等)前

在需要显示的地方写上下列代码

<script>
  // 自动更新
  var timeagoInstance = timeago();
  timeagoInstance.render(document.querySelectorAll('.time'),'zh_CN');
  console.log(time);
</script>

下面是实例代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="https://cdn.bootcss.com/timeago.js/3.0.2/timeago.js"></script>
</head>

<body>

<div class="time" datetime="2022-06-01 17:38:00"></div>



<script>
  // 自动更新
  var timeagoInstance = timeago();// 实例
  timeagoInstance.render(document.querySelectorAll('.time'),'zh_CN');
  console.log(time);
</script>
</body>
</html>

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注