react里使用Day.js显示时间

介绍

官方文档: https://dayjs.fenxianglu.cn/

安装方式

  1. npm install dayjs
  2. cnpm install dayjs
  3. yarn add dayjs
  4. pnpm add dayjs

引入及使用

js 复制代码
// 引入
var dayjs = require('dayjs');
// 或者
// import dayjs from 'dayjs' 
// 使用
// 打印当前时间对象的格式化时间
console.log(dayjs().format())  // 2024-12-27T15:26:34+08:00
console.log(dayjs().format("YYYY-MM-DD"))  //2024-12-27
console.log(dayjs().format("YYYY年MM月DD日"))  //2024年12月27日
console.log(dayjs().format("YYYY-MM-DD HH:mm:ss"))  //2024-12-27 15:26:34

判断是否是闰年
IsLeapYear 增加了 .isLeapYear API 返回一个boolean来展示一个 Day.js 对象的年份是不是闰年。

js 复制代码
// 引入dayjs
import dayjs from 'dayjs';
var isLeapYear = require('dayjs/plugin/isLeapYear') // nodejs
dayjs.extend(isLeapYear)
console.log(dayjs('2024-12-27').isLeapYear())  //true
相关推荐
Jmyd01231 小时前
Web端3D营销展厅技术实现路径:从素材上云到线索回流的数据链路
前端·3d·性能优化·三维数字化
半个落月2 小时前
LangChain Agent 中间件实战(上):生命周期、状态、短路与工具包
javascript·langchain
砚凝霜2 小时前
【软考信息安全】第二十二章 Web服务器安全分析与增强——Apache与IIS
服务器·前端·安全
半个落月2 小时前
LangChain Agent 中间件实战(下):DeepAgents文件权限、长期记忆与对话摘要
javascript·langchain
u0111026754 小时前
JPG、PNG、WebP 怎么选?按透明度、体积和使用场景做判断
前端·javascript·vue.js·图像处理·ai作画
jerrywus4 小时前
让 AI 写完代码后交一份报告:我改造了 answer-me-with-html
前端·claude·cursor
派小心.5 小时前
小程序分享链路中来源参数的传递校验
大数据·前端·数据库·人工智能·小程序·数据分析
hhb_6185 小时前
一键生成数据看板,ECharts实战演示
前端·javascript·echarts
Java后端的Ai之路5 小时前
08_React组件API
前端·react.js·前端框架
小马不起床5 小时前
零基础玩转 FastAPI_09:前端基础工程构建
前端·状态模式·fastapi