Day.js

Day.js

  • 文档
  • GitHub
  • Languages icon英语
    • 中文
    • Русский
    • 帮助翻译

›插件

安装

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

解析

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

获取 + 设置

  • 获取 + 设置
  • 毫秒
  • 秒
  • 分钟
  • 小时
  • 日期
  • 星期几
  • 星期几(区域感知)
  • ISO 星期几
  • 一年中的第几天
  • 一年中的第几周
  • 一年中的第几周(ISO)
  • 月份
  • 季度
  • 年份
  • 周年份
  • 周年份(ISO)
  • 一年中的周数(ISO)
  • 获取
  • 设置
  • 最大值
  • 最小值

操作

  • 操作
  • 添加
  • 减去
  • 时间开始
  • 时间结束
  • 本地
  • UTC
  • UTC 偏移

显示

  • 显示
  • 格式
  • 从现在开始的时间
  • 从 X 开始的时间
  • 到现在的剩余时间
  • 到 X 的剩余时间
  • 日历时间
  • 差异
  • Unix 时间戳(毫秒)
  • Unix 时间戳
  • 月份中的天数
  • 作为 JavaScript 日期
  • 作为数组
  • 作为 JSON
  • 作为 ISO 8601 字符串
  • 作为对象
  • 作为字符串

查询

  • 查询
  • 在之前
  • 相同
  • 在之后
  • 相同或在之前
  • 相同或在之后
  • 在之间
  • 是一个 Dayjs
  • 是闰年

i18n

  • i18n
  • 在 NodeJS 中加载区域设置
  • 在浏览器中加载区域设置
  • 全局更改区域设置
  • 局部更改区域设置
  • 检查当前 Day.js 区域设置
  • 列出当前区域设置的月份和星期几
  • 访问特定区域设置的功能

插件

  • 插件
  • 在 NodeJS 中加载插件
  • 在浏览器中加载插件
  • AdvancedFormat
  • ArraySupport
  • BadMutable
  • BigIntSupport
  • BuddhistEra
  • Calendar
  • 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

自定义

  • 自定义
  • 月份名称
  • 月份缩写
  • 星期几名称
  • 星期几缩写
  • 星期几最小缩写
  • 相对时间
  • Calendar

持续时间

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

时区

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

UTC

UTC 添加了 .utc .local .isUTC API,用于在 UTC 中解析或显示。

var utc = require('dayjs/plugin/utc')
dayjs.extend(utc)

// default local time
dayjs().format() //2019-03-06T17:11:55+08:00

// UTC mode
dayjs.utc().format() // 2019-03-06T09:11:55Z

// convert local time to UTC time
dayjs().utc().format() // 2019-03-06T09:11:55Z 

// While in UTC mode, all display methods will display in UTC time instead of local time.
// And all getters and setters will internally use the Date#getUTC* and Date#setUTC* methods instead of the Date#get* and Date#set* methods.
dayjs.utc().isUTC() // true
dayjs.utc().local().format() //2019-03-06T17:11:55+08:00
dayjs.utc('2018-01-01', 'YYYY-MM-DD') // with CustomParseFormat plugin

默认情况下,Day.js 会以本地时间解析和显示。

如果你想在 UTC 中解析或显示,则可以使用 dayjs.utc() 代替 dayjs()。

dayjs.utc dayjs.utc(dateType?: string | number | Date | Dayjs, format? string)

返回 UTC 模式下的 Dayjs 对象。

使用 UTC 时间 .utc()

返回一个克隆的 Dayjs 对象,其中带有使用 UTC 时间的标志。

使用本地时间 .local()

返回一个克隆的 Dayjs 对象,其中带有使用本地时间的标志。

返回一个具有新 UTC 偏移量的克隆的 Dayjs 对象。

isUTC 模式 .isUTC()

返回一个 boolean,指示当前 Dayjs 对象是否处于 UTC 模式。

← UpdateLocaleweekOfYear →
Day.js
社区
GitHubGitter🇨🇳 中国镜像站点Sitemap
版权所有 © 2024 Day.js