如何使用 Day.js 在浏览器中呈现日期? [英] How can I render date in the browser using Day.js?
本文介绍了如何使用 Day.js 在浏览器中呈现日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 Dayjs 将日期渲染到 元素中.我该怎么做?我在 html 文档底部的脚本标签中从 CDN 导入了 dayjs.
<!--这是我的html代码--><div class="d-flex event"><span class="mr-3 text-danger date"></span><span class="text-danger">24°C,Fort Portal</span>
解决方案
<身体><!--这是我的html代码--><div class="d-flex 事件"><span class="mr-3 text-danger date"></span><br><span class="text-danger">24°C,Fort Portal</span>
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script><脚本>让datesClasses = document.getElementsByClassName("date")Array.prototype.forEach.call(datesClasses, element => {element.innerHTML = dayjs().format('YYYY/MM/DD HH:mm:ss A')})</html>
I want to render a date into the <span class="mr-3 text-danger date">
element using Dayjs. How do I go about doing this? I have dayjs imported from a CDN in a script tag at the bottom of the html document.
<!--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>
这篇关于如何使用 Day.js 在浏览器中呈现日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文