如何使用 Day.js 在浏览器中呈现日期?
How can I render date in the browser using Day.js?
我想使用 Dayjs 将日期渲染到 <span class="mr-3 text-danger date">
元素中。我该怎么做呢?我在 html 文档底部的脚本标签中从 CDN 导入了 dayjs。
<!--This is my html code-->
<div class="d-flex event">
<span class="mr-3 text-danger date"></span>
<span class="text-danger">24°C, Fort Portal</span>
</div>
<!DOCTYPE html>
<html>
<body>
<!--This is my html code-->
<div class="d-flex event">
<span class="mr-3 text-danger date"></span><br>
<span class="text-danger">24°C, Fort Portal</span>
</div>
</body>
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script>
let datesClasses = document.getElementsByClassName("date")
Array.prototype.forEach.call(datesClasses, element => {
element.innerHTML = dayjs().format('YYYY/MM/DD HH:mm:ss A')
})
</script>
</html>
我想使用 Dayjs 将日期渲染到 <span class="mr-3 text-danger date">
元素中。我该怎么做呢?我在 html 文档底部的脚本标签中从 CDN 导入了 dayjs。
<!--This is my html code-->
<div class="d-flex event">
<span class="mr-3 text-danger date"></span>
<span class="text-danger">24°C, Fort Portal</span>
</div>
<!DOCTYPE html>
<html>
<body>
<!--This is my html code-->
<div class="d-flex event">
<span class="mr-3 text-danger date"></span><br>
<span class="text-danger">24°C, Fort Portal</span>
</div>
</body>
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script>
let datesClasses = document.getElementsByClassName("date")
Array.prototype.forEach.call(datesClasses, element => {
element.innerHTML = dayjs().format('YYYY/MM/DD HH:mm:ss A')
})
</script>
</html>