1. 首页
  2. 编程
  3. 前端日期时间扩展 dayjs
  • 111
  • 前端日期时间扩展 dayjs二维码
  • 前端日期时间扩展 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

    小而美的日期处理库:day.js 的优势及使用介绍当涉及到处理日期时,moment.js 是一个广为人知的库。它提供了各 - 掘金

    评论 0

    您需要登录后才能评论, 现在 登录注册
    Loading...
    好机会,快来抢个沙发吧

    {{v.user.name}} {{ v.from_now }}   回复 ({{ v.reply_count }})

    {{ v.content }}
    {{ v.reply_count }} 条回复收起

    {{vv.user.name}} <%=data[i].from_now%>   回复

    <%=data[i].content%>