前端日期时间扩展 dayjs
NPM
// 安装
npm install dayjs
// 文件内引入
import dayjs from 'dayjs';
// 打印当前日期时间
console.log(dayjs().format());
CDN
这种方式需要插件名前增加 window.dayjs_plugin_ 前缀
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/utc.js"></script>
<script>dayjs.extend(window.dayjs_plugin_utc)</script>
// html中显示当前日期
<div id="currentDate"></div>
<script>
const currentDate = document.querySelector("#currentDate");
currentDate.textContent = dayjs().format("YYYY-MM-DD");
</script>
相关链接
小而美的日期处理库:day.js 的优势及使用介绍当涉及到处理日期时,moment.js 是一个广为人知的库。它提供了各 - 掘金
评论 0
{{v.user.name}} {{ v.from_now }} 回复 ({{ v.reply_count }})
{{ v.content }}{{vv.user.name}} <%=data[i].from_now%> 回复
<%=data[i].content%>