Day.js 中文网

Day.js 中文网

  • 开发文档
  • Nodejs.cn 旗下网站

›显示

安装

  • 安装
  • Node.js
  • 浏览器
  • TypeScript
  • 下载

解析

  • 解析
  • 此刻
  • 字符串
  • 字符串 + 格式
  • Unix 时间戳(毫秒)
  • Unix 时间戳(秒)
  • 日期
  • 对象
  • 数组
  • UTC
  • Dayjs 克隆
  • 验证

取值+赋值

  • 取值+赋值
  • 毫秒
  • 秒
  • 分钟
  • 小时
  • 日期
  • 星期
  • 星期(区域设置感知)
  • ISO 星期
  • 年积日
  • 周
  • 周 (ISO)
  • 月份
  • 季度
  • 年份
  • 周年
  • 周年 (ISO)
  • 周数 (ISO)
  • 取值
  • 赋值
  • 最大值
  • 最小值

操作

  • 操作
  • 加法
  • 减法
  • 时间开端
  • 时间终端
  • 当地时间
  • UTC
  • UTC 偏移

显示

  • 显示
  • 格式
  • 从此刻到过去的时间
  • 从 X 到过去的时间
  • 从此刻到未来的时间
  • 从 X 到未来的时间
  • 日历时间
  • 时间差
  • Unix 时间戳(毫秒)
  • Unix 时间戳
  • 月份的天数
  • 作为 Javascript 日期
  • 作为数组
  • 作为 JSON
  • 作为 ISO 8601 字符串
  • 作为对象
  • 作为字符串

查询

  • 查询
  • 是否之前
  • 是否相同
  • 是否之后
  • 是否相同或之前
  • 是否相同或之后
  • 是否之间
  • 是否 Dayjs
  • 是否闰年

国际化

  • 国际化
  • 在 NodeJS 中加载语言环境
  • 在浏览器中加载语言环境
  • 全局地更改语言环境
  • 局部地更改语言环境
  • 检查当前 Day.js 语言环境
  • 列出当前区域设置的月份和工作日
  • 访问特定于语言环境的功能

插件

  • 插件
  • 在 NodeJS 中加载插件
  • 在浏览器中加载插件
  • AdvancedFormat
  • ArraySupport
  • BadMutable
  • BigIntSupport
  • BuddhistEra
  • 日历
  • CustomParseFormat
  • DayOfYear
  • DevHelper
  • Duration
  • IsBetween
  • IsLeapYear
  • IsSameOrAfter
  • IsSameOrBefore
  • IsToday
  • IsTomorrow
  • IsYesterday
  • IsoWeek
  • IsoWeeksInYear
  • LocaleData
  • LocalizedFormat
  • MinMax
  • ObjectSupport
  • PluralGetSet
  • PreParsePostFormat
  • QuarterOfYear
  • RelativeTime
  • Timezone
  • ToArray
  • ToObject
  • UpdateLocale
  • UTC
  • weekOfYear
  • WeekYear
  • Weekday

定制

  • 定制
  • 月份名称
  • 月份缩写
  • 星期名称
  • 星期缩写
  • 最小星期缩写
  • 相对时间
  • 日历

时长

  • 时长
  • 创建
  • 克隆
  • 人性化
  • 格式
  • 毫秒数
  • 秒数
  • 分钟数
  • 小时数
  • 天数
  • 周数
  • 月数
  • 年数
  • 添加时间
  • 减去时间
  • 将时长与时间差一起使用
  • 作为时间单位
  • 获取时间单位
  • 作为 JSON
  • 是否时长
  • 作为 ISO 8601 字符串
  • 语言环境

时区

  • 时区
  • 在区域中解析
  • 转换为区域
  • 猜测用户区域
  • 设置默认时区

格式

根据传入的 token 字符串获取格式化的日期。

¥Get the formatted date according to the string of tokens passed in.

要转义字符,请将它们括在方括号中(例如 [MM])。

¥To escape characters, wrap them in square brackets (e.g. [MM]).

dayjs().format() 
// current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'

dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]') 
// 'YYYYescape 2019-01-25T00:00:00-02:00Z'

dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'

所有可用格式的列表

¥List of all available formats

格式输出描述
YY18两位数年份
YYYY2018四位数年份
M1-12月份,从 1 开始
MM01-12月份,2 位数字
MMMJan-Dec月份名称缩写
MMMMJanuary-December完整的月份名称
D1-31该月的哪一天
DD01-31月份中的日期,2 位数字
d0-6一周中的某一天,星期日为 0
ddSu-Sa星期几的最小名称
dddSun-Sat星期几的简称
ddddSunday-Saturday星期几的名称
H0-23小时
HH00-23小时,2 位数字
h1-12小时、12 小时制
hh01-12小时,12 小时制,2 位数字
m0-59分钟
mm00-59分钟,2 位数字
s0-59第二
ss00-59第二个,2 位数字
SSS000-999毫秒,3 位数字
Z+05:00与 UTC 的偏移量,±HH:mm
ZZ+0500与 UTC 的偏移量,±HHmm
A上午下午
aam pm
......Other formats ( dependent AdvancedFormat plugin )
  • 插件 AdvancedFormat 中有更多可用格式 Q Do k kk X x ...

    ¥More available formats Q Do k kk X x ... in plugin AdvancedFormat

本地化格式

¥Localized formats

由于首选格式因区域设置而异,因此可以根据其区域设置使用一些本地化格式标记。

¥Because preferred formatting differs based on locale, there are a few localized format tokens that can be used based on its locale.

This requires the LocalizedFormat plugin to work

dayjs.extend(LocalizedFormat)
dayjs().format('L LT')

本地化格式列表

¥List of localized formats

格式英语语言环境示例输出
LTh:mm A8:02 PM
LTSh:mm:ss A8:02:18 PM
LMM/DD/YYYY08/16/2018
LLMMMM D, YYYYAugust 16, 2018
LLLMMMM D, YYYY h:mm AAugust 16, 2018 8:02 PM
LLLLdddd, MMMM D, YYYY h:mm A2018 年 8 月 16 日星期四晚上 8:02
lM/D/YYYY8/16/2018
llMMM D, YYYYAug 16, 2018
lllMMM D, YYYY h:mm AAug 16, 2018 8:02 PM
llllddd, MMM D, YYYY h:mm A2018 年 8 月 16 日星期四 晚上 8:02
← 显示从此刻到过去的时间 →
Day.js v1.11 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站