本页内容
Sommatic 文档
打开控制台

Luxon 日期

使用 Luxon 处理日期与时间:$now 与 $today 都是 Luxon 的 DateTime 值,下方所有方法均可直接调用。

以 Markdown 查看
在以下应用中打开

版本 3.7.2 MIT 官方文档

$now 使用服务器时区,格式化前请先设置所需时区。

JavaScript
{{ $now.setZone('America/Bogota').toFormat('yyyy-LL-dd HH:mm') }}

创建 DateTime

DateTime.buildFormatParser(fmt, options = {})

使用给定的 locale 为格式 fmt 构建一个解析器。该解析器可传给 DateTime.fromFormatParser,按此格式解析日期;适用于需要按同一格式解析大量日期的场景,可提升性能。

  • fmt String 字符串应符合的格式(见上文说明)。
  • options Object 为解析器设置 locale 和 numberingSystem 的选项。

→ TokenParser

DateTime.DATE_FULL

DateTime#toLocaleString 预设格式,形如 October 14, 1983。

DateTime.DATE_HUGE

DateTime#toLocaleString 预设格式,形如 Tuesday, October 14, 1983。

DateTime.DATE_MED

DateTime#toLocaleString 预设格式,形如 Oct 14, 1983。

DateTime.DATE_MED_WITH_WEEKDAY

DateTime#toLocaleString 预设格式,形如 Fri, Oct 14, 1983。

DateTime.DATE_SHORT

DateTime#toLocaleString 预设格式,形如 10/14/1983。

DateTime.DATETIME_FULL

DateTime#toLocaleString 预设格式,形如 October 14, 1983, 9:30 AM EDT;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_FULL_WITH_SECONDS

DateTime#toLocaleString 预设格式,形如 October 14, 1983, 9:30:33 AM EDT;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_HUGE

DateTime#toLocaleString 预设格式,形如 Friday, October 14, 1983, 9:30 AM Eastern Daylight Time;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_HUGE_WITH_SECONDS

DateTime#toLocaleString 预设格式,形如 Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_MED

DateTime#toLocaleString 预设格式,形如 Oct 14, 1983, 9:30 AM;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_MED_WITH_SECONDS

DateTime#toLocaleString 预设格式,形如 Oct 14, 1983, 9:30:33 AM;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_MED_WITH_WEEKDAY

DateTime#toLocaleString 预设格式,形如 Fri, 14 Oct 1983, 9:30 AM;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_SHORT

DateTime#toLocaleString 预设格式,形如 10/14/1983, 9:30 AM;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.DATETIME_SHORT_WITH_SECONDS

DateTime#toLocaleString 预设格式,形如 10/14/1983, 9:30:33 AM;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.expandFormat(fmt, localeOpts = {})

为指定 locale 生成完全展开的格式记号。不会给字符加引号,因此带引号的记号无法正确往返转换。

  • fmt 要展开的格式字符串。
  • localeOpts locale 相关选项(如 `locale`、`numberingSystem`)。

→ string

DateTime.fromFormat(text, fmt, opts = {})

根据输入字符串和格式字符串创建 DateTime。未指定 locale 时默认使用 en-US,与系统 locale 无关。格式记号及其含义见 记号表。

  • text string 要解析的字符串。
  • fmt string 字符串应符合的格式(可用格式见记号表链接)。
  • opts Object 影响创建过程的选项。
  • opts.zone string|Zone 可选 默认值 'local' 输入字符串本身未指定偏移时使用此时区;同时会把结果 DateTime 转换到该时区。
  • opts.setZone boolean 可选 默认值 false 若字符串本身指定了时区,则用该时区覆盖 zone。
  • opts.locale string 可选 默认值 'en-US' 解析时使用的 locale 字符串;同时会把结果 DateTime 设为该 locale。
  • opts.numberingSystem string 解析时使用的数字系统;同时会把结果 DateTime 设为该数字系统。
  • opts.weekSettings string 为生成的 DateTime 实例设置的周规则(week settings)。
  • opts.outputCalendar string 为生成的 DateTime 实例设置的输出日历。

→ DateTime

DateTime.fromFormatExplain(text, fmt, options = {})

说明 fromFormat() 会如何解析某个字符串,用于调试格式。

  • text string 要解析的字符串。
  • fmt string 字符串应符合的格式(见上文说明)。
  • options Object `fromFormat()` 接受的选项。

→ Object

DateTime.fromFormatParser(text, formatParser, opts = {})

根据输入字符串和格式解析器创建 DateTime。该解析器必须以与本次调用相同的 locale 创建。

  • text String 要解析的字符串。
  • formatParser TokenParser 由 `DateTime.buildFormatParser` 创建的解析器。
  • opts Object `fromFormat()` 接受的选项。

→ DateTime

DateTime.fromHTTP(text, opts = {})

根据 HTTP 头中的日期创建 DateTime。

  • text string HTTP 头中的日期。
  • opts Object 影响创建过程的选项。
  • opts.zone string|Zone 可选 默认值 'local' 把时间转换到此时区。由于 HTTP 日期始终是 UTC,这不影响字符串的解释,只决定结果 DateTime 以哪个时区表示。
  • opts.setZone boolean 可选 默认值 false 用字符串中指定的固定偏移时区覆盖 zone。HTTP 日期始终为 UTC,因此等同于把 `zone` 设为 `'utc'`;保留此选项是为了与同类方法保持一致。
  • opts.locale string 可选 默认值 'system's locale' 为生成的 DateTime 实例设置的 locale。
  • opts.outputCalendar string 为生成的 DateTime 实例设置的输出日历。
  • opts.numberingSystem string 为生成的 DateTime 实例设置的数字系统(numbering system)。
  • opts.weekSettings string 为生成的 DateTime 实例设置的周规则(week settings)。

→ DateTime

{{ $now.constructor.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT') }}
结果 DateTime
"1994-11-06T08:49:37.000Z"
{{ $now.constructor.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT') }}
结果 DateTime
"1994-11-06T08:49:37.000Z"
{{ $now.constructor.fromHTTP('Sun Nov  6 08:49:37 1994') }}
结果 DateTime
"1994-11-06T08:49:37.000Z"

DateTime.fromISO(text, opts = {})

根据 ISO 8601 字符串创建 DateTime。

  • text string ISO 字符串。
  • opts Object 影响创建过程的选项。
  • opts.zone string|Zone 可选 默认值 'local' 输入字符串本身未指定偏移时使用此时区;同时会把时间转换到该时区。
  • opts.setZone boolean 可选 默认值 false 若字符串本身指定了偏移,则用该固定偏移时区覆盖 zone。
  • opts.locale string 可选 默认值 'system's locale' 为生成的 DateTime 实例设置的 locale。
  • opts.outputCalendar string 可选 为生成的 DateTime 实例设置的输出日历。
  • opts.numberingSystem string 可选 为生成的 DateTime 实例设置的数字系统(numbering system)。
  • opts.weekSettings string 可选 为生成的 DateTime 实例设置的周规则(week settings)。

→ DateTime

{{ $now.constructor.fromISO('2016-05-25T09:08:34.123') }}
结果 DateTime
"2016-05-25T09:08:34.123Z"
{{ $now.constructor.fromISO('2016-05-25T09:08:34.123+06:00') }}
结果 DateTime
"2016-05-25T03:08:34.123Z"
{{ $now.constructor.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true}) }}
结果 DateTime
"2016-05-25T09:08:34.123+06:00"

DateTime.fromJSDate(date, options = {})

根据 JavaScript Date 对象创建 DateTime,使用默认时区。

  • date Date JavaScript `Date` 对象。
  • options Object DateTime 的配置选项。
  • options.zone string|Zone 可选 默认值 'local' DateTime 所要放入的时区。

→ DateTime

DateTime.fromMillis(milliseconds, options = {})

根据自纪元(1970 年 1 月 1 日 00:00:00 UTC)以来的毫秒数创建 DateTime,使用默认时区。

  • milliseconds number 自 1970 年 UTC 起的毫秒数。
  • options Object DateTime 的配置选项。
  • options.zone string|Zone 可选 默认值 'local' DateTime 所要放入的时区。
  • options.locale string 可选 为生成的 DateTime 实例设置的 locale。
  • options.outputCalendar string 为生成的 DateTime 实例设置的输出日历。
  • options.numberingSystem string 为生成的 DateTime 实例设置的数字系统(numbering system)。
  • options.weekSettings string 为生成的 DateTime 实例设置的周规则(week settings)。

→ DateTime

DateTime.fromObject(obj, opts = {})

根据包含 year、hour 等键的 JavaScript 对象创建 DateTime,未提供的字段取合理默认值。

  • obj Object 用于创建 DateTime 的对象。
  • obj.year number 年份,例如 1987。
  • obj.month number 月份,1 到 12。
  • obj.day number 当月中的日期,1 到 31,取决于月份。
  • obj.ordinal number 一年中的第几天,1 到 365 或 366。
  • obj.weekYear number ISO 周年。
  • obj.weekNumber number ISO 周数,1 到 52 或 53,取决于年份。
  • obj.weekday number ISO 星期几,1 到 7,1 为周一,7 为周日。
  • obj.localWeekYear number 按 locale 规则计算的周年。
  • obj.localWeekNumber number 按 locale 规则计算的周数,1 到 52 或 53,取决于年份。
  • obj.localWeekday number 按 locale 规则计算的星期几,1 到 7,1 为一周第一天,7 为最后一天。
  • obj.hour number 一天中的小时,0 到 23。
  • obj.minute number 一小时中的分钟,0 到 59。
  • obj.second number 一分钟中的秒,0 到 59。
  • obj.millisecond number 一秒中的毫秒,0 到 999。
  • opts Object 创建此 DateTime 的选项。
  • opts.zone string|Zone 可选 默认值 'local' 在指定时区的上下文中解释这些数值;可取 `setZone()` 第一个参数接受的任意值。
  • opts.locale string 可选 默认值 'system\'s locale' 为生成的 DateTime 实例设置的 locale。
  • opts.outputCalendar string 为生成的 DateTime 实例设置的输出日历。
  • opts.numberingSystem string 为生成的 DateTime 实例设置的数字系统(numbering system)。
  • opts.weekSettings string 为生成的 DateTime 实例设置的周规则(week settings)。

→ DateTime

{{ $now.constructor.fromObject({ year: 1982, month: 5, day: 25}).toISODate() }}
结果 string
"1982-05-25"
{{ $now.constructor.fromObject({ year: 1982 }).toISODate() }}
结果 string
"1982-01-01"
{{ $now.constructor.fromObject({ hour: 10, minute: 26, second: 6 }) }}
结果 DateTime
"2026-11-26T10:26:06.000Z"

DateTime.fromRFC2822(text, opts = {})

根据 RFC 2822 字符串创建 DateTime。

  • text string RFC 2822 字符串。
  • opts Object 影响创建过程的选项。
  • opts.zone string|Zone 可选 默认值 'local' 把时间转换到此时区。由于字符串本身总会指定偏移,这不影响字符串的解释,只决定结果 DateTime 以哪个时区表示。
  • opts.setZone boolean 可选 默认值 false 若字符串本身指定了偏移,则用该固定偏移时区覆盖 zone。
  • opts.locale string 可选 默认值 'system's locale' 为生成的 DateTime 实例设置的 locale。
  • opts.outputCalendar string 为生成的 DateTime 实例设置的输出日历。
  • opts.numberingSystem string 为生成的 DateTime 实例设置的数字系统(numbering system)。
  • opts.weekSettings string 为生成的 DateTime 实例设置的周规则(week settings)。

→ DateTime

{{ $now.constructor.fromRFC2822('25 Nov 2016 13:23:12 GMT') }}
结果 DateTime
"2016-11-25T13:23:12.000Z"
{{ $now.constructor.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600') }}
结果 DateTime
"2016-11-25T07:23:12.000Z"
{{ $now.constructor.fromRFC2822('25 Nov 2016 13:23 Z') }}
结果 DateTime
"2016-11-25T13:23:00.000Z"

DateTime.fromSeconds(seconds, options = {})

根据自纪元(1970 年 1 月 1 日 00:00:00 UTC)以来的秒数创建 DateTime,使用默认时区。

  • seconds number 自 1970 年 UTC 起的秒数。
  • options Object DateTime 的配置选项。
  • options.zone string|Zone 可选 默认值 'local' DateTime 所要放入的时区。
  • options.locale string 可选 为生成的 DateTime 实例设置的 locale。
  • options.outputCalendar string 为生成的 DateTime 实例设置的输出日历。
  • options.numberingSystem string 为生成的 DateTime 实例设置的数字系统(numbering system)。
  • options.weekSettings string 为生成的 DateTime 实例设置的周规则(week settings)。

→ DateTime

DateTime.fromSQL(text, opts = {})

根据 SQL 日期、时间或日期时间字符串创建 DateTime。未指定 locale 时默认使用 en-US,与系统 locale 无关。

  • text string 要解析的字符串。
  • opts Object 影响创建过程的选项。
  • opts.zone string|Zone 可选 默认值 'local' 输入字符串本身未指定偏移时使用此时区;同时会把结果 DateTime 转换到该时区。
  • opts.setZone boolean 可选 默认值 false 若字符串本身指定了时区,则用该时区覆盖 zone。
  • opts.locale string 可选 默认值 'en-US' 解析时使用的 locale 字符串;同时会把结果 DateTime 设为该 locale。
  • opts.numberingSystem string 解析时使用的数字系统;同时会把结果 DateTime 设为该数字系统。
  • opts.weekSettings string 为生成的 DateTime 实例设置的周规则(week settings)。
  • opts.outputCalendar string 为生成的 DateTime 实例设置的输出日历。

→ DateTime

{{ $now.constructor.fromSQL('2017-05-15') }}
结果 DateTime
"2017-05-15T00:00:00.000Z"
{{ $now.constructor.fromSQL('2017-05-15 09:12:34') }}
结果 DateTime
"2017-05-15T09:12:34.000Z"
{{ $now.constructor.fromSQL('2017-05-15 09:12:34.342') }}
结果 DateTime
"2017-05-15T09:12:34.342Z"

DateTime.invalid(reason, explanation = null)

创建一个无效的 DateTime。

  • reason string 说明此 DateTime 无效原因的简短字符串,不应包含参数或其他依赖数据的内容。
  • explanation string 可选 默认值 null 更详细的说明,可包含参数及其他有助于调试的信息。

→ DateTime

DateTime.isDateTime(o)

检查对象是否为 DateTime 实例,可跨上下文边界(如不同 realm)使用。

  • o object 要检查的对象。

→ boolean

DateTime.local()

创建一个本地时区的 DateTime。

  • year number 可选 日历年份。若省略(即不带参数调用 `local()`),则使用当前时间。
  • month number 可选 默认值 1 月份,从 1 开始计数。
  • day number 可选 默认值 1 当月中的日期,从 1 开始计数。
  • hour number 可选 默认值 0 小时,采用 24 小时制。
  • minute number 可选 默认值 0 分钟,取值 0 到 59。
  • second number 可选 默认值 0 秒,取值 0 到 59。
  • millisecond number 可选 默认值 0 毫秒,取值 0 到 999。

→ DateTime

{{ $now }}
结果 DateTime
"2026-11-26T14:30:00.000Z"
{{ $now.constructor.local({ zone: "America/New_York" }) }}
结果 DateTime
"2026-11-26T09:30:00.000-05:00"
{{ $now.constructor.local(2017) }}
结果 DateTime
"2017-01-01T00:00:00.000Z"

DateTime.max(...dateTimes)

返回多个 DateTime 中最晚的一个。

  • dateTimes ...DateTime 从中选取最大值的 DateTime。

→ DateTime

DateTime.min(...dateTimes)

返回多个 DateTime 中最早的一个。

  • dateTimes ...DateTime 从中选取最小值的 DateTime。

→ DateTime

DateTime.now()

创建一个表示当前时刻、位于默认时区的 DateTime。

→ DateTime

{{ $now.toISO() }}
结果 string
"2026-11-26T14:30:00.000Z"

DateTime.parseFormatForOpts(formatOpts, localeOpts = {})

根据一组 Intl.DateTimeFormat 选项生成对应的格式字符串。

  • formatOpts `Intl.DateTimeFormat` 格式选项。
  • localeOpts locale 相关选项(如 `locale`、`numberingSystem`)。

→ string

DateTime.TIME_24_SIMPLE

DateTime#toLocaleString 预设格式,形如 09:30,始终为 24 小时制。

DateTime.TIME_24_WITH_LONG_OFFSET

DateTime#toLocaleString 预设格式,形如 09:30:23 Eastern Daylight Time,始终为 24 小时制。

DateTime.TIME_24_WITH_SECONDS

DateTime#toLocaleString 预设格式,形如 09:30:23,始终为 24 小时制。

DateTime.TIME_24_WITH_SHORT_OFFSET

DateTime#toLocaleString 预设格式,形如 09:30:23 EDT,始终为 24 小时制。

DateTime.TIME_SIMPLE

DateTime#toLocaleString 预设格式,形如 09:30 AM;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.TIME_WITH_LONG_OFFSET

DateTime#toLocaleString 预设格式,形如 09:30:23 AM Eastern Daylight Time;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.TIME_WITH_SECONDS

DateTime#toLocaleString 预设格式,形如 09:30:23 AM;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.TIME_WITH_SHORT_OFFSET

DateTime#toLocaleString 预设格式,形如 09:30:23 AM EDT;仅当 locale 使用 12 小时制时才显示为 12 小时制。

DateTime.utc()

创建一个 UTC 时区的 DateTime。

  • year number 可选 日历年份。若省略(即不带参数调用 `utc()`),则使用当前时间。
  • month number 可选 默认值 1 月份,从 1 开始计数。
  • day number 可选 默认值 1 当月中的日期。
  • hour number 可选 默认值 0 小时,采用 24 小时制。
  • minute number 可选 默认值 0 分钟,取值 0 到 59。
  • second number 可选 默认值 0 秒,取值 0 到 59。
  • millisecond number 可选 默认值 0 毫秒,取值 0 到 999。
  • options Object DateTime 的配置选项。
  • options.locale string 可选 为生成的 DateTime 实例设置的 locale。
  • options.outputCalendar string 可选 为生成的 DateTime 实例设置的输出日历。
  • options.numberingSystem string 可选 为生成的 DateTime 实例设置的数字系统(numbering system)。
  • options.weekSettings string 可选 为生成的 DateTime 实例设置的周规则(week settings)。

→ DateTime

{{ $now.constructor.utc() }}
结果 DateTime
"2026-11-26T14:30:00.000Z"
{{ $now.constructor.utc(2017) }}
结果 DateTime
"2017-01-01T00:00:00.000Z"
{{ $now.constructor.utc(2017, 3) }}
结果 DateTime
"2017-03-01T00:00:00.000Z"

读取各部分

$now.day

获取当月中的日期(1 到 30 左右)。

{{ $now.constructor.local(2017, 5, 25).day }}
结果 number
25

$now.daysInMonth

返回此 DateTime 所在月份的天数。

{{ $now.constructor.local(2016, 2).daysInMonth }}
结果 number
29
{{ $now.constructor.local(2016, 3).daysInMonth }}
结果 number
31

$now.daysInYear

返回此 DateTime 所在年份的天数。

{{ $now.constructor.local(2016).daysInYear }}
结果 number
366
{{ $now.constructor.local(2013).daysInYear }}
结果 number
365

$now.hour

获取一天中的小时(0 到 23)。

{{ $now.constructor.local(2017, 5, 25, 9).hour }}
结果 number
9

$now.invalidExplanation

返回此 DateTime 无效的原因说明;若 DateTime 有效则返回 null。

{{ $now.invalidExplanation }}
结果 null
null

$now.invalidReason

返回此 DateTime 无效时的错误代码;若 DateTime 有效则返回 null。

{{ $now.invalidReason }}
结果 null
null

$now.isInDST

判断此 DateTime 是否处于夏令时(DST)。

{{ $now.isInDST }}
结果 boolean
false

$now.isInLeapYear

此 DateTime 位于闰年时返回 true,否则返回 false。

{{ $now.constructor.local(2016).isInLeapYear }}
结果 boolean
true
{{ $now.constructor.local(2013).isInLeapYear }}
结果 boolean
false

$now.isOffsetFixed

判断此 DateTime 所在时区的偏移是否固定不变(即不会像夏令时那样变化)。

{{ $now.isOffsetFixed }}
结果 boolean
true

$now.isValid

返回此 DateTime 是否有效。以下情况会产生无效的 DateTime:

  • 由无效的日历信息创建,例如第 13 个月或 2 月 30 日;
  • 由对另一个无效日期的运算得到。
{{ $now.isValid }}
结果 boolean
true

$now.isWeekend

按 locale 规则判断此日期是否为周末:是则返回 true,否则返回 false。

→ boolean

{{ $now.isWeekend }}
结果 boolean
false

$now.locale

获取 DateTime 的 locale,例如 en-GB。格式化 DateTime 时会使用该 locale。

{{ $now.locale }}
结果 string
"en-US"

$now.localWeekday

按 locale 规则获取星期几:1 为一周的第一天,7 为最后一天。若该 locale 以周日为一周的第一天,则周日返回 1。

→ number

{{ $now.localWeekday }}
结果 number
5

$now.localWeekNumber

按 locale 规则获取周年中的周数。不同 locale 的周编号方式不同:一周的起始日可能不同(见 localWeekday),一年第一周所需的最少天数也可能不同。

→ number

{{ $now.localWeekNumber }}
结果 number
48

$now.localWeekYear

按 locale 规则获取周年(week year)。不同 locale 的周编号(因而周年)方式不同,见 localWeekNumber。

→ number

{{ $now.localWeekYear }}
结果 number
2026

$now.millisecond

获取一秒中的毫秒(0 到 999)。

{{ $now.constructor.local(2017, 5, 25, 9, 30, 52, 654).millisecond }}
结果 number
654

$now.minute

获取一小时中的分钟(0 到 59)。

{{ $now.constructor.local(2017, 5, 25, 9, 30).minute }}
结果 number
30

$now.month

获取月份(1 到 12)。

{{ $now.constructor.local(2017, 5, 25).month }}
结果 number
5

$now.monthLong

获取便于阅读的完整月份名称,例如 October。未指定 locale 时使用系统 locale。

{{ $now.constructor.local(2017, 10, 30).monthLong }}
结果 string
"October"

$now.monthShort

获取便于阅读的简写月份名称,例如 Oct。未指定 locale 时使用系统 locale。

{{ $now.constructor.local(2017, 10, 30).monthShort }}
结果 string
"Oct"

$now.numberingSystem

获取 DateTime 的数字系统,例如 beng。格式化 DateTime 时会使用该数字系统。

{{ $now.numberingSystem }}
结果 null
null

$now.offset

获取此 DateTime 相对 UTC 的偏移,单位为分钟。

{{ $now.offset }}
结果 number
0
{{ $now.constructor.utc().offset }}
结果 number
0

$now.offsetNameLong

获取时区当前偏移的完整名称,例如 Eastern Standard Time 或 Eastern Daylight Time。未指定 locale 时使用系统 locale。

{{ $now.offsetNameLong }}
结果 string
"UTC"

$now.offsetNameShort

获取时区当前偏移的简称,例如 EST 或 EDT。未指定 locale 时使用系统 locale。

{{ $now.offsetNameShort }}
结果 string
"UTC"

$now.ordinal

获取序数日,即该日期是一年中的第几天。

{{ $now.constructor.local(2017, 5, 25).ordinal }}
结果 number
145

$now.outputCalendar

获取 DateTime 的输出日历,例如 islamic。格式化 DateTime 时会使用该日历。

{{ $now.outputCalendar }}
结果 null
null

$now.quarter

获取季度(1 到 4)。

{{ $now.constructor.local(2017, 5, 25).quarter }}
结果 number
2

$now.second

获取一分钟中的秒(0 到 59)。

{{ $now.constructor.local(2017, 5, 25, 9, 30, 52).second }}
结果 number
52

$now.weekday

获取星期几:1 为周一,7 为周日(ISO 规则)。

{{ $now.constructor.local(2014, 11, 31).weekday }}
结果 number
null

$now.weekdayLong

获取便于阅读的完整星期名称,例如 Monday。未指定 locale 时使用系统 locale。

{{ $now.constructor.local(2017, 10, 30).weekdayLong }}
结果 string
"Monday"

$now.weekdayShort

获取便于阅读的简写星期名称,例如 Mon。未指定 locale 时使用系统 locale。

{{ $now.constructor.local(2017, 10, 30).weekdayShort }}
结果 string
"Mon"

$now.weekNumber

获取 ISO 周年中的周数(1 到 52 左右)。

{{ $now.constructor.local(2017, 5, 25).weekNumber }}
结果 number
21

$now.weeksInLocalWeekYear

返回此 DateTime 所在 locale 周年的周数。

{{ $now.constructor.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear }}
结果 number
52
{{ $now.constructor.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear }}
结果 number
53

$now.weeksInWeekYear

返回此 DateTime 所在 ISO 周年的周数。

{{ $now.constructor.local(2004).weeksInWeekYear }}
结果 number
53
{{ $now.constructor.local(2013).weeksInWeekYear }}
结果 number
52

$now.weekYear

获取 ISO 周年(week year)。

{{ $now.constructor.local(2014, 12, 31).weekYear }}
结果 number
2015

$now.year

获取年份。

{{ $now.constructor.local(2017, 5, 25).year }}
结果 number
2017

$now.zone

获取与此 DateTime 关联的时区对象。

{{ $now.zone }}
结果 object
{"fixed":0}

$now.zoneName

获取时区名称,例如 America/Bogota。

{{ $now.zoneName }}
结果 string
"UTC"

转换与格式化

$now.diff(otherDateTime, unit = "milliseconds", opts = {})

以 Duration 形式返回两个 DateTime 之间的差值。

  • otherDateTime DateTime 与此 DateTime 比较的另一个 DateTime。
  • unit string|string[] 可选 默认值 ['milliseconds' Duration 中要包含的单位或单位数组,例如 `'hours'` 或 `'days'`。
  • opts Object 影响 Duration 创建的选项。
  • opts.conversionAccuracy string 可选 默认值 'casual' 使用的换算体系。

→ Duration

$now.diffNow(unit = "milliseconds", opts = {})

返回此 DateTime 与当前时间之间的差值(Duration)。参见 DateTime#diff。

  • unit string|string[] 可选 默认值 ['milliseconds' Duration 中要包含的单位或单位数组,例如 `'hours'` 或 `'days'`。
  • opts Object 影响 Duration 创建的选项。
  • opts.conversionAccuracy string 可选 默认值 'casual' 使用的换算体系。

→ Duration

$now.endOf(unit, opts)

把此 DateTime“设置”为某个时间单位的末尾(即该单位的最后一毫秒),返回新的 DateTime。

  • unit string 要移到其末尾的单位,可为 `'year'`、`'quarter'`、`'month'`、`'week'`、`'day'`、`'hour'`、`'minute'`、`'second'` 或 `'millisecond'`。
  • opts Object 选项对象。
  • opts.useLocaleWeeks boolean 可选 默认值 false 为 `true` 时按 locale 计算周,即使用该 locale 的每周起始日。

→ DateTime

{{ $now.constructor.local(2014, 3, 3).endOf('month').toISO() }}
结果 string
"2014-03-31T23:59:59.999Z"
{{ $now.constructor.local(2014, 3, 3).endOf('year').toISO() }}
结果 string
"2014-12-31T23:59:59.999Z"
{{ $now.constructor.local(2014, 3, 3).endOf('week').toISO() }}
结果 string
"2014-03-09T23:59:59.999Z"

$now.equals(other)

相等性检查:当且仅当两个 DateTime 表示同一毫秒、时区与 locale 相同且均有效时才相等。若只比较毫秒值,请使用 +dt1 === +dt2。

  • other DateTime 另一个 DateTime。

→ boolean

$now.get(unit)

获取指定单位的值。

  • unit string 单位名称,例如 `'minute'` 或 `'day'`。

→ number

{{ $now.constructor.local(2017, 7, 4).get('month') }}
结果 number
7
{{ $now.constructor.local(2017, 7, 4).get('day') }}
结果 number
4

$now.getPossibleOffsets()

返回在此 DateTime 所在时区中与其本地时间相同、但 UTC 偏移不同的所有 DateTime。夏令时切换期间本地时间可能有歧义,例如 Europe/Berlin 的 2023-10-29T02:30:00 偏移可能是 +01:00 或 +02:00;此时该方法会返回两个可能的 DateTime。

→ DateTime[]

{{ $now.getPossibleOffsets() }}
结果 list
["2026-11-26T14:30:00.000Z"]

$now.hasSame(otherDateTime, unit, opts)

判断此 DateTime 与另一个 DateTime 是否处于同一时间单位内;更高阶的单位也必须相同才返回 true。注意此比较忽略时区,比较的是本地日历时间;必要时先用 DateTime#setZone 转换其中一个日期。

  • otherDateTime DateTime 另一个 DateTime。
  • unit string 用于判断是否相同的时间单位。
  • opts Object 选项对象。
  • opts.useLocaleWeeks boolean 可选 默认值 false 为 `true` 时按 locale 计算周,即使用该 locale 的每周起始日;只使用此 DateTime 的 locale。

→ boolean

$now.minus(duration)

从此 DateTime 减去一段时间,返回得到的新 DateTime。参见 DateTime#plus。

  • duration Duration|Object|number 要减去的时长:可以是 Luxon Duration、毫秒数,或 `Duration.fromObject()` 接受的对象。

$now.plus(duration)

给此 DateTime 加上一段时间,返回得到的新 DateTime。

加小时、分钟、秒或毫秒时,时间戳按相应毫秒数增加;加天、月或年时则按日历推移,并考虑夏令时和闰年。因此若中间存在夏令时切换,dt.plus({ hours: 24 }) 与 dt.plus({ days: 1 }) 的结果可能不同。

  • duration Duration|Object|number 要加上的时长:可以是 Luxon Duration、毫秒数,或 `Duration.fromObject()` 接受的对象。

→ DateTime

{{ $now.plus(123) }}
结果 DateTime
"2026-11-26T14:30:00.123Z"
{{ $now.plus({ minutes: 15 }) }}
结果 DateTime
"2026-11-26T14:45:00.000Z"
{{ $now.plus({ days: 1 }) }}
结果 DateTime
"2026-11-27T14:30:00.000Z"

$now.reconfigure({ locale, numberingSystem, outputCalendar } = {})

“设置” locale、numberingSystem 或 outputCalendar,返回新构造的 DateTime。

  • properties Object 要设置的属性。

→ DateTime

{{ $now.constructor.local(2017, 5, 25).reconfigure({ locale: 'en-GB' }) }}
结果 DateTime
"2017-05-25T00:00:00.000Z"

$now.resolvedLocaleOptions(opts = {})

返回此 DateTime 解析后的 Intl 选项,便于理解各格式化方法的行为。

  • opts Object 与 `toLocaleString` 相同的选项。

→ Object

$now.set(values)

“设置”指定单位的值,返回新构造的 DateTime。此方法只能设置单位;如需“设置”元数据,请参见 DateTime#reconfigure 和 DateTime#setZone。

也支持设置基于 locale 的周单位,即 localWeekday、localWeekNumber 和 localWeekYear,但不能与 weekday 等 ISO 周单位混用。

  • values Object 单位到数值的映射对象。

→ DateTime

$now.setLocale(locale)

“设置” locale,返回新构造的 DateTime。等同于 reconfigure({ locale }) 的便捷写法。

→ DateTime

{{ $now.constructor.local(2017, 5, 25).setLocale('en-GB') }}
结果 DateTime
"2017-05-25T00:00:00.000Z"

$now.setZone(zone, { keepLocalTime = false, keepCalendarTime = false } = {})

把 DateTime 的时区“设置”为指定时区,返回新构造的 DateTime。

默认保持底层时间(即时间戳)不变,但新实例会显示不同的本地时间,并在计算时(如 DateTime#plus)考虑夏令时。对于常用时区,可使用 DateTime#toLocal 和 DateTime#toUTC 这两个便捷方法。

  • zone string|Zone 可选 默认值 'local' 时区标识。字符串形式可以是宿主环境支持的任意 IANA 时区、`'UTC+3'` 形式的固定偏移名称,或 `'local'`、`'utc'`;也可以传入 `Zone` 类的实例。
  • opts Object 选项对象。
  • opts.keepLocalTime boolean 可选 默认值 false 为 `true` 时调整底层时间,使本地时间在目标时区中保持不变。一般很少需要。

→ DateTime

$now.startOf(unit, { useLocaleWeeks = false } = {})

把此 DateTime“设置”为某个时间单位的开头,返回新的 DateTime。

  • unit string 要移到其开头的单位,可为 `'year'`、`'quarter'`、`'month'`、`'week'`、`'day'`、`'hour'`、`'minute'`、`'second'` 或 `'millisecond'`。
  • opts Object 选项对象。
  • opts.useLocaleWeeks boolean 可选 默认值 false 为 `true` 时按 locale 计算周,即使用该 locale 的每周起始日。

→ DateTime

{{ $now.constructor.local(2014, 3, 3).startOf('month').toISODate() }}
结果 string
"2014-03-01"
{{ $now.constructor.local(2014, 3, 3).startOf('year').toISODate() }}
结果 string
"2014-01-01"
{{ $now.constructor.local(2014, 3, 3).startOf('week').toISODate() }}
结果 string
"2014-03-03"

$now.toBSON()

返回与此 DateTime 等价、可被 BSON 序列化的值(JavaScript Date)。

→ Date

{{ $now.toBSON() }}
结果 object
"2026-11-26T14:30:00.000Z"

$now.toFormat(fmt, opts = {})

按指定的格式字符串返回此 DateTime 的字符串表示。这未必是你想要的:更灵活的格式化方式见 DateTime#toLocaleString。格式记号(token)及其含义见 记号表。未指定 locale 时默认使用 en-US,与系统 locale 无关。

  • fmt string 格式字符串。
  • opts Object 用于覆盖此 DateTime 配置选项的 opts。

→ string

{{ $now.toFormat('yyyy LLL dd') }}
结果 string
"2026 Nov 26"
{{ $now.setLocale('fr').toFormat('yyyy LLL dd') }}
结果 string
"2026 nov. 26"
{{ $now.toFormat('yyyy LLL dd', { locale: "fr" }) }}
结果 string
"2026 nov. 26"

$now.toHTTP()

返回适用于 HTTP 头的字符串表示,始终以 GMT 表示,符合 RFC 1123。

→ string

{{ $now.constructor.utc(2014, 7, 13).toHTTP() }}
结果 string
"Sun, 13 Jul 2014 00:00:00 GMT"
{{ $now.constructor.utc(2014, 7, 13, 19).toHTTP() }}
结果 string
"Sun, 13 Jul 2014 19:00:00 GMT"

$now.toISO({ format = "extended", suppressSeconds = false, suppressMilliseconds = false, includeOffset = true, extendedZone = false, precision = "milliseconds", } = {})

返回此 DateTime 符合 ISO 8601 的字符串表示。

  • opts Object 选项对象。
  • opts.suppressMilliseconds boolean 可选 默认值 false 毫秒为 0 时在输出中省略毫秒。
  • opts.suppressSeconds boolean 可选 默认值 false 秒为 0 时在输出中省略秒。
  • opts.includeOffset boolean 可选 默认值 true 是否包含时区偏移,例如 `Z` 或 `-04:00`。
  • opts.extendedZone boolean 可选 默认值 false 追加时区格式扩展(如 `[America/New_York]`)。
  • opts.format string 可选 默认值 'extended' 在基本格式(basic)与扩展格式(extended)之间选择。
  • opts.precision string 可选 默认值 'milliseconds' 把输出截断到指定精度:`'years'`、`'months'`、`'days'`、`'hours'`、`'minutes'`、`'seconds'` 或 `'milliseconds'`。与 `suppressSeconds` 或 `suppressMilliseconds` 同时使用时,`precision` 决定输出显示的最大单位,但秒或毫秒为 0 时仍会被省略。

→ string|null

{{ $now.constructor.utc(1983, 5, 25).toISO() }}
结果 string
"1983-05-25T00:00:00.000Z"
{{ $now.toISO() }}
结果 string
"2026-11-26T14:30:00.000Z"
{{ $now.toISO({ includeOffset: false }) }}
结果 string
"2026-11-26T14:30:00.000"

$now.toISODate({ format = "extended", precision = "day" } = {})

返回此 DateTime 日期部分符合 ISO 8601 的字符串表示。

  • opts Object 选项对象。
  • opts.format string 可选 默认值 'extended' 在基本格式(basic)与扩展格式(extended)之间选择。
  • opts.precision string 可选 默认值 'day' 把输出截断到指定精度:`'years'`、`'months'` 或 `'days'`。

→ string|null

{{ $now.constructor.utc(1982, 5, 25).toISODate() }}
结果 string
"1982-05-25"
{{ $now.constructor.utc(1982, 5, 25).toISODate({ format: 'basic' }) }}
结果 string
"19820525"
{{ $now.constructor.utc(1982, 5, 25).toISODate({ precision: 'month' }) }}
结果 string
"1982-05"

$now.toISOTime({ suppressMilliseconds = false, suppressSeconds = false, includeOffset = true, includePrefix = false, extendedZone = false, format = "extended", precision = "milliseconds", } = {})

返回此 DateTime 时间部分符合 ISO 8601 的字符串表示。

  • opts Object 选项对象。
  • opts.suppressMilliseconds boolean 可选 默认值 false 毫秒为 0 时在输出中省略毫秒。
  • opts.suppressSeconds boolean 可选 默认值 false 秒为 0 时在输出中省略秒。
  • opts.includeOffset boolean 可选 默认值 true 是否包含时区偏移,例如 `Z` 或 `-04:00`。
  • opts.extendedZone boolean 可选 默认值 true 追加时区格式扩展(如 `[America/New_York]`)。
  • opts.includePrefix boolean 可选 默认值 false 是否包含 `T` 前缀。
  • opts.format string 可选 默认值 'extended' 在基本格式(basic)与扩展格式(extended)之间选择。
  • opts.precision string 可选 默认值 'milliseconds' 把输出截断到指定精度:`'hours'`、`'minutes'`、`'seconds'` 或 `'milliseconds'`。与 `suppressSeconds` 或 `suppressMilliseconds` 同时使用时,`precision` 决定输出显示的最大单位,但秒或毫秒为 0 时仍会被省略。

→ string

{{ $now.constructor.utc().set({ hour: 7, minute: 34 }).toISOTime() }}
结果 string
"07:34:00.000Z"
{{ $now.constructor.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) }}
结果 string
"07:34Z"
{{ $now.constructor.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) }}
结果 string
"073400.000Z"

$now.toISOWeekDate()

返回此 DateTime 周日期(week date)符合 ISO 8601 的字符串表示,例如 2026-W48-4。

→ string

{{ $now.constructor.utc(1982, 5, 25).toISOWeekDate() }}
结果 string
"1982-W21-2"

$now.toJSDate()

返回与此 DateTime 等价的 JavaScript Date。

→ Date

{{ $now.toJSDate() }}
结果 object
"2026-11-26T14:30:00.000Z"

$now.toJSON()

返回适用于 JSON 的 ISO 8601 字符串表示。

→ string

{{ $now.toJSON() }}
结果 string
"2026-11-26T14:30:00.000Z"

$now.toLocal()

把 DateTime 的时区“设置”为宿主机的本地时区,返回新构造的 DateTime。等同于 setZone('local')。

→ DateTime

{{ $now.toLocal() }}
结果 DateTime
"2026-11-26T14:30:00.000Z"

$now.toLocaleParts(opts = {})

返回格式化结果的“片段”(parts)数组,即各个记号及其元数据,便于调用方对格式化输出的各部分做后处理。未指定 locale 时使用系统 locale。

  • opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`. `Intl.DateTimeFormat` 构造函数选项,与 `toLocaleString` 相同。
{{ $now.toLocaleParts() }}
结果 list
[
  {
    "type": "month",
    "value": "11"
  },
  {
    "type": "literal",
    "value": "/"
  },
  {
    "type": "day",
    "value": "26"
  },
  {
    "type": "literal",
    "value": "/"
  },
  {
    "type": "year",
    "value": "2026"
  }
]

$now.toLocaleString(formatOpts = Formats.DATE_SHORT, opts = {})

返回表示此日期的本地化字符串。接受与 Intl.DateTimeFormat 构造函数相同的选项,以及 Luxon 定义的预设,例如 DateTime.DATE_FULL 或 DateTime.TIME_SIMPLE。具体行为因运行环境而异,但通常会按所设 locale 返回合适的表示。未指定 locale 时使用系统 locale。

  • formatOpts {Object} - Intl.DateTimeFormat constructor options and configuration options `Intl.DateTimeFormat` 构造函数选项及配置选项。
  • opts Object 用于覆盖此 DateTime 配置选项的 opts。

→ string

{{ $now.toLocaleString() }}
结果 string
"11/26/2026"
{{ $now.setLocale('en-gb').toLocaleString() }}
结果 string
"26/11/2026"
{{ $now.toLocaleString($now.constructor.DATE_FULL) }}
结果 string
"November 26, 2026"

$now.toMillis()

返回此 DateTime 的纪元毫秒数(epoch milliseconds)。

→ number

{{ $now.toMillis() }}
结果 number
1795703400000

$now.toObject(opts = {})

返回包含此 DateTime 的年、月、日等字段的 JavaScript 对象。

  • opts - options for generating the object 生成对象时使用的选项。
  • opts.includeConfig boolean 可选 默认值 false 是否在输出中包含配置属性(locale、numberingSystem、outputCalendar)。

→ Object

{{ $now.toObject() }}
结果 object
{
  "year": 2026,
  "month": 11,
  "day": 26,
  "hour": 14,
  "minute": 30,
  "second": 0,
  "millisecond": 0
}

$now.toRelative(options = {})

返回此时间相对于当前时间的字符串表示,例如“2 天后”。仅在平台支持 Intl.RelativeTimeFormat 时才能本地化。默认向零取整。

  • options Object 影响输出结果的选项。
  • options.base DateTime 可选 默认值 DateTime.now() 作为比较基准的 DateTime,默认为当前时间。
  • options.style string 可选 默认值 "long" 单位的样式,必须为 `"long"`、`"short"` 或 `"narrow"`。
  • options.unit string|string[] 使用指定的单位或单位数组;省略或传入数组时,方法会自动选择最合适的单位。可传数组,或 `"years"`、`"quarters"`、`"months"`、`"weeks"`、`"days"`、`"hours"`、`"minutes"`、`"seconds"` 之一。
  • options.round boolean 可选 默认值 true 是否对输出中的数字取整。
  • options.rounding string 可选 默认值 "trunc" 对输出数字取整时使用的方法:`"trunc"`(向零)、`"expand"`(远离零)、`"round"`、`"floor"` 或 `"ceil"`。
  • options.padding number 可选 默认值 0 以毫秒计的填充量;结果落在该阈值内时向上取整。不要与 `{round: false}` 同时使用,否则小数输出会包含这部分填充。
  • options.locale string 覆盖此 DateTime 的 locale。
  • options.numberingSystem string 覆盖此 DateTime 的 numberingSystem;Intl 可能不予采纳。
{{ $now.plus({ days: 1 }).toRelative() }}
结果 string
"in 1 day"
{{ $now.setLocale("es").toRelative({ days: 1 }) }}
结果 string
"dentro de 0 segundos"
{{ $now.plus({ days: 1 }).toRelative({ locale: "fr" }) }}
结果 string
"dans 1 jour"

$now.toRelativeCalendar(options = {})

返回此日期相对于今天的字符串表示,例如“昨天”或“下个月”。仅在平台支持 Intl.RelativeTimeFormat 时才能本地化。

  • options Object 影响输出结果的选项。
  • options.base DateTime 可选 默认值 DateTime.now() 作为比较基准的 DateTime,默认为当前时间。
  • options.locale string 覆盖此 DateTime 的 locale。
  • options.unit string 使用指定的单位;省略时由方法自动选择。可为 `"years"`、`"quarters"`、`"months"`、`"weeks"` 或 `"days"` 之一。
  • options.numberingSystem string 覆盖此 DateTime 的 numberingSystem;Intl 可能不予采纳。
{{ $now.plus({ days: 1 }).toRelativeCalendar() }}
结果 string
"tomorrow"
{{ $now.setLocale("es").plus({ days: 1 }).toRelative() }}
结果 string
"dentro de 1 día"
{{ $now.plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) }}
结果 string
"demain"

$now.toRFC2822()

返回此 DateTime 符合 RFC 2822 的字符串表示。

→ string

{{ $now.constructor.utc(2014, 7, 13).toRFC2822() }}
结果 string
"Sun, 13 Jul 2014 00:00:00 +0000"
{{ $now.constructor.local(2014, 7, 13).toRFC2822() }}
结果 string
"Sun, 13 Jul 2014 00:00:00 +0000"

$now.toSeconds()

返回此 DateTime 的纪元秒数(小数部分为毫秒)。

→ number

{{ $now.toSeconds() }}
结果 number
1795703400

$now.toSQL(opts = {})

返回适用于 SQL DateTime 的字符串表示。

  • opts Object 选项对象。
  • opts.includeZone boolean 可选 默认值 false 是否包含时区名,例如 `America/New_York`;会覆盖 `includeOffset`。
  • opts.includeOffset boolean 可选 默认值 true 是否包含时区偏移,例如 `Z` 或 `-04:00`。
  • opts.includeOffsetSpace boolean 可选 默认值 true 是否在时间与偏移之间加空格,例如 `05:15:16.345 -04:00`。

→ string

{{ $now.constructor.utc(2014, 7, 13).toSQL() }}
结果 string
"2014-07-13 00:00:00.000 Z"
{{ $now.constructor.local(2014, 7, 13).toSQL() }}
结果 string
"2014-07-13 00:00:00.000 Z"
{{ $now.constructor.local(2014, 7, 13).toSQL({ includeOffset: false }) }}
结果 string
"2014-07-13 00:00:00.000"

$now.toSQLDate()

返回适用于 SQL Date 的字符串表示。

→ string|null

{{ $now.constructor.utc(2014, 7, 13).toSQLDate() }}
结果 string
"2014-07-13"

$now.toSQLTime({ includeOffset = true, includeZone = false, includeOffsetSpace = true } = {})

返回适用于 SQL Time 的字符串表示。

  • opts Object 选项对象。
  • opts.includeZone boolean 可选 默认值 false 是否包含时区名,例如 `America/New_York`;会覆盖 `includeOffset`。
  • opts.includeOffset boolean 可选 默认值 true 是否包含时区偏移,例如 `Z` 或 `-04:00`。
  • opts.includeOffsetSpace boolean 可选 默认值 true 是否在时间与偏移之间加空格,例如 `05:15:16.345 -04:00`。

→ string

{{ $now.constructor.utc().toSQL() }}
结果 string
"2026-11-26 14:30:00.000 Z"
{{ $now.toSQL() }}
结果 string
"2026-11-26 14:30:00.000 Z"
{{ $now.toSQL({ includeOffset: false }) }}
结果 string
"2026-11-26 14:30:00.000"

$now.toString()

返回适合调试的字符串表示(有效时等同于 toISO())。

→ string

{{ $now.toString() }}
结果 string
"2026-11-26T14:30:00.000Z"

$now.toUnixInteger()

返回此 DateTime 的纪元秒数(取整)。

→ number

{{ $now.toUnixInteger() }}
结果 number
1795703400

$now.toUTC(offset = 0, opts = {})

把 DateTime 的时区“设置”为 UTC,返回新构造的 DateTime。等同于 setZone('utc')。

  • offset number 可选 默认值 0 可选,相对 UTC 的偏移分钟数。
  • opts Object 可选 默认值 {} 传给 `setZone()` 的选项。

→ DateTime

{{ $now.toUTC() }}
结果 DateTime
"2026-11-26T14:30:00.000Z"

$now.until(otherDateTime)

返回从此 DateTime 到另一个 DateTime 的 Interval。

  • otherDateTime DateTime Interval 的另一个端点。

→ Interval|DateTime

$now.valueOf()

返回此 DateTime 的纪元毫秒数,是 DateTime#toMillis 的别名;因此可以直接用 <、> 比较两个 DateTime。

→ number

{{ $now.valueOf() }}
结果 number
1795703400000

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档