# Luxon 日期

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

Source: https://docs.sommatic.ai/zh/expressions/luxon/

版本: 3.7.2 (MIT). 官方文档: https://moment.github.io/luxon/api-docs/index.html

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

```
{{ $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 的选项。

Returns `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`）。

Returns `string`.

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

根据输入字符串和格式字符串创建 DateTime。未指定 locale 时默认使用 en-US，与系统 locale 无关。格式记号及其含义见 [记号表](https://moment.github.io/luxon/#/parsing?id=table-of-tokens)。

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

Returns `DateTime`.

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

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

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

Returns `Object`.

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

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

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

Returns `DateTime`.

### `DateTime.fromHTTP(text, opts = {})`

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

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

Returns `DateTime`.

```javascript
{{ $now.constructor.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT') }}
```

结果 (DateTime):

```json
"1994-11-06T08:49:37.000Z"
```

```javascript
{{ $now.constructor.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT') }}
```

结果 (DateTime):

```json
"1994-11-06T08:49:37.000Z"
```

```javascript
{{ $now.constructor.fromHTTP('Sun Nov  6 08:49:37 1994') }}
```

结果 (DateTime):

```json
"1994-11-06T08:49:37.000Z"
```

### `DateTime.fromISO(text, opts = {})`

根据 ISO 8601 字符串创建 DateTime。

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

Returns `DateTime`.

```javascript
{{ $now.constructor.fromISO('2016-05-25T09:08:34.123') }}
```

结果 (DateTime):

```json
"2016-05-25T09:08:34.123Z"
```

```javascript
{{ $now.constructor.fromISO('2016-05-25T09:08:34.123+06:00') }}
```

结果 (DateTime):

```json
"2016-05-25T03:08:34.123Z"
```

```javascript
{{ $now.constructor.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true}) }}
```

结果 (DateTime):

```json
"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, optional, default 'local'): DateTime 所要放入的时区。

Returns `DateTime`.

### `DateTime.fromMillis(milliseconds, options = {})`

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

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

Returns `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, optional, default 'local'): 在指定时区的上下文中解释这些数值；可取 `setZone()` 第一个参数接受的任意值。
- `opts.locale` (string, optional, default 'system\'s locale'): 为生成的 DateTime 实例设置的 locale。
- `opts.outputCalendar` (string): 为生成的 DateTime 实例设置的输出日历。
- `opts.numberingSystem` (string): 为生成的 DateTime 实例设置的数字系统（numbering system）。
- `opts.weekSettings` (string): 为生成的 DateTime 实例设置的周规则（week settings）。

Returns `DateTime`.

```javascript
{{ $now.constructor.fromObject({ year: 1982, month: 5, day: 25}).toISODate() }}
```

结果 (string):

```json
"1982-05-25"
```

```javascript
{{ $now.constructor.fromObject({ year: 1982 }).toISODate() }}
```

结果 (string):

```json
"1982-01-01"
```

```javascript
{{ $now.constructor.fromObject({ hour: 10, minute: 26, second: 6 }) }}
```

结果 (DateTime):

```json
"2026-11-26T10:26:06.000Z"
```

### `DateTime.fromRFC2822(text, opts = {})`

根据 RFC 2822 字符串创建 DateTime。

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

Returns `DateTime`.

```javascript
{{ $now.constructor.fromRFC2822('25 Nov 2016 13:23:12 GMT') }}
```

结果 (DateTime):

```json
"2016-11-25T13:23:12.000Z"
```

```javascript
{{ $now.constructor.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600') }}
```

结果 (DateTime):

```json
"2016-11-25T07:23:12.000Z"
```

```javascript
{{ $now.constructor.fromRFC2822('25 Nov 2016 13:23 Z') }}
```

结果 (DateTime):

```json
"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, optional, default 'local'): DateTime 所要放入的时区。
- `options.locale` (string, optional): 为生成的 DateTime 实例设置的 locale。
- `options.outputCalendar` (string): 为生成的 DateTime 实例设置的输出日历。
- `options.numberingSystem` (string): 为生成的 DateTime 实例设置的数字系统（numbering system）。
- `options.weekSettings` (string): 为生成的 DateTime 实例设置的周规则（week settings）。

Returns `DateTime`.

### `DateTime.fromSQL(text, opts = {})`

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

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

Returns `DateTime`.

```javascript
{{ $now.constructor.fromSQL('2017-05-15') }}
```

结果 (DateTime):

```json
"2017-05-15T00:00:00.000Z"
```

```javascript
{{ $now.constructor.fromSQL('2017-05-15 09:12:34') }}
```

结果 (DateTime):

```json
"2017-05-15T09:12:34.000Z"
```

```javascript
{{ $now.constructor.fromSQL('2017-05-15 09:12:34.342') }}
```

结果 (DateTime):

```json
"2017-05-15T09:12:34.342Z"
```

### `DateTime.invalid(reason, explanation = null)`

创建一个无效的 DateTime。

- `reason` (string): 说明此 DateTime 无效原因的简短字符串，不应包含参数或其他依赖数据的内容。
- `explanation` (string, optional, default null): 更详细的说明，可包含参数及其他有助于调试的信息。

Returns `DateTime`.

### `DateTime.isDateTime(o)`

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

- `o` (object): 要检查的对象。

Returns `boolean`.

### `DateTime.local()`

创建一个本地时区的 DateTime。

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

Returns `DateTime`.

```javascript
{{ $now }}
```

结果 (DateTime):

```json
"2026-11-26T14:30:00.000Z"
```

```javascript
{{ $now.constructor.local({ zone: "America/New_York" }) }}
```

结果 (DateTime):

```json
"2026-11-26T09:30:00.000-05:00"
```

```javascript
{{ $now.constructor.local(2017) }}
```

结果 (DateTime):

```json
"2017-01-01T00:00:00.000Z"
```

### `DateTime.max(...dateTimes)`

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

- `dateTimes` (...DateTime): 从中选取最大值的 DateTime。

Returns `DateTime`.

### `DateTime.min(...dateTimes)`

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

- `dateTimes` (...DateTime): 从中选取最小值的 DateTime。

Returns `DateTime`.

### `DateTime.now()`

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

Returns `DateTime`.

```javascript
{{ $now.toISO() }}
```

结果 (string):

```json
"2026-11-26T14:30:00.000Z"
```

### `DateTime.parseFormatForOpts(formatOpts, localeOpts = {})`

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

- `formatOpts`: `Intl.DateTimeFormat` 格式选项。
- `localeOpts`: locale 相关选项（如 `locale`、`numberingSystem`）。

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

Returns `DateTime`.

```javascript
{{ $now.constructor.utc() }}
```

结果 (DateTime):

```json
"2026-11-26T14:30:00.000Z"
```

```javascript
{{ $now.constructor.utc(2017) }}
```

结果 (DateTime):

```json
"2017-01-01T00:00:00.000Z"
```

```javascript
{{ $now.constructor.utc(2017, 3) }}
```

结果 (DateTime):

```json
"2017-03-01T00:00:00.000Z"
```

## 读取各部分

### `$now.day`

获取当月中的日期（1 到 30 左右）。

```javascript
{{ $now.constructor.local(2017, 5, 25).day }}
```

结果 (number):

```json
25
```

### `$now.daysInMonth`

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

```javascript
{{ $now.constructor.local(2016, 2).daysInMonth }}
```

结果 (number):

```json
29
```

```javascript
{{ $now.constructor.local(2016, 3).daysInMonth }}
```

结果 (number):

```json
31
```

### `$now.daysInYear`

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

```javascript
{{ $now.constructor.local(2016).daysInYear }}
```

结果 (number):

```json
366
```

```javascript
{{ $now.constructor.local(2013).daysInYear }}
```

结果 (number):

```json
365
```

### `$now.hour`

获取一天中的小时（0 到 23）。

```javascript
{{ $now.constructor.local(2017, 5, 25, 9).hour }}
```

结果 (number):

```json
9
```

### `$now.invalidExplanation`

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

```javascript
{{ $now.invalidExplanation }}
```

结果 (null):

```json
null
```

### `$now.invalidReason`

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

```javascript
{{ $now.invalidReason }}
```

结果 (null):

```json
null
```

### `$now.isInDST`

判断此 DateTime 是否处于夏令时（DST）。

```javascript
{{ $now.isInDST }}
```

结果 (boolean):

```json
false
```

### `$now.isInLeapYear`

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

```javascript
{{ $now.constructor.local(2016).isInLeapYear }}
```

结果 (boolean):

```json
true
```

```javascript
{{ $now.constructor.local(2013).isInLeapYear }}
```

结果 (boolean):

```json
false
```

### `$now.isOffsetFixed`

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

```javascript
{{ $now.isOffsetFixed }}
```

结果 (boolean):

```json
true
```

### `$now.isValid`

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

* 由无效的日历信息创建，例如第 13 个月或 2 月 30 日；
* 由对另一个无效日期的运算得到。

```javascript
{{ $now.isValid }}
```

结果 (boolean):

```json
true
```

### `$now.isWeekend`

按 locale 规则判断此日期是否为周末：是则返回 `true`，否则返回 `false`。

Returns `boolean`.

```javascript
{{ $now.isWeekend }}
```

结果 (boolean):

```json
false
```

### `$now.locale`

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

```javascript
{{ $now.locale }}
```

结果 (string):

```json
"en-US"
```

### `$now.localWeekday`

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

Returns `number`.

```javascript
{{ $now.localWeekday }}
```

结果 (number):

```json
5
```

### `$now.localWeekNumber`

按 locale 规则获取周年中的周数。不同 locale 的周编号方式不同：一周的起始日可能不同（见 `localWeekday`），一年第一周所需的最少天数也可能不同。

Returns `number`.

```javascript
{{ $now.localWeekNumber }}
```

结果 (number):

```json
48
```

### `$now.localWeekYear`

按 locale 规则获取周年（week year）。不同 locale 的周编号（因而周年）方式不同，见 `localWeekNumber`。

Returns `number`.

```javascript
{{ $now.localWeekYear }}
```

结果 (number):

```json
2026
```

### `$now.millisecond`

获取一秒中的毫秒（0 到 999）。

```javascript
{{ $now.constructor.local(2017, 5, 25, 9, 30, 52, 654).millisecond }}
```

结果 (number):

```json
654
```

### `$now.minute`

获取一小时中的分钟（0 到 59）。

```javascript
{{ $now.constructor.local(2017, 5, 25, 9, 30).minute }}
```

结果 (number):

```json
30
```

### `$now.month`

获取月份（1 到 12）。

```javascript
{{ $now.constructor.local(2017, 5, 25).month }}
```

结果 (number):

```json
5
```

### `$now.monthLong`

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

```javascript
{{ $now.constructor.local(2017, 10, 30).monthLong }}
```

结果 (string):

```json
"October"
```

### `$now.monthShort`

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

```javascript
{{ $now.constructor.local(2017, 10, 30).monthShort }}
```

结果 (string):

```json
"Oct"
```

### `$now.numberingSystem`

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

```javascript
{{ $now.numberingSystem }}
```

结果 (null):

```json
null
```

### `$now.offset`

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

```javascript
{{ $now.offset }}
```

结果 (number):

```json
0
```

```javascript
{{ $now.constructor.utc().offset }}
```

结果 (number):

```json
0
```

### `$now.offsetNameLong`

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

```javascript
{{ $now.offsetNameLong }}
```

结果 (string):

```json
"UTC"
```

### `$now.offsetNameShort`

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

```javascript
{{ $now.offsetNameShort }}
```

结果 (string):

```json
"UTC"
```

### `$now.ordinal`

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

```javascript
{{ $now.constructor.local(2017, 5, 25).ordinal }}
```

结果 (number):

```json
145
```

### `$now.outputCalendar`

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

```javascript
{{ $now.outputCalendar }}
```

结果 (null):

```json
null
```

### `$now.quarter`

获取季度（1 到 4）。

```javascript
{{ $now.constructor.local(2017, 5, 25).quarter }}
```

结果 (number):

```json
2
```

### `$now.second`

获取一分钟中的秒（0 到 59）。

```javascript
{{ $now.constructor.local(2017, 5, 25, 9, 30, 52).second }}
```

结果 (number):

```json
52
```

### `$now.weekday`

获取星期几：1 为周一，7 为周日（ISO 规则）。

```javascript
{{ $now.constructor.local(2014, 11, 31).weekday }}
```

结果 (number):

```json
null
```

### `$now.weekdayLong`

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

```javascript
{{ $now.constructor.local(2017, 10, 30).weekdayLong }}
```

结果 (string):

```json
"Monday"
```

### `$now.weekdayShort`

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

```javascript
{{ $now.constructor.local(2017, 10, 30).weekdayShort }}
```

结果 (string):

```json
"Mon"
```

### `$now.weekNumber`

获取 ISO 周年中的周数（1 到 52 左右）。

```javascript
{{ $now.constructor.local(2017, 5, 25).weekNumber }}
```

结果 (number):

```json
21
```

### `$now.weeksInLocalWeekYear`

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

```javascript
{{ $now.constructor.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear }}
```

结果 (number):

```json
52
```

```javascript
{{ $now.constructor.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear }}
```

结果 (number):

```json
53
```

### `$now.weeksInWeekYear`

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

```javascript
{{ $now.constructor.local(2004).weeksInWeekYear }}
```

结果 (number):

```json
53
```

```javascript
{{ $now.constructor.local(2013).weeksInWeekYear }}
```

结果 (number):

```json
52
```

### `$now.weekYear`

获取 ISO 周年（week year）。

```javascript
{{ $now.constructor.local(2014, 12, 31).weekYear }}
```

结果 (number):

```json
2015
```

### `$now.year`

获取年份。

```javascript
{{ $now.constructor.local(2017, 5, 25).year }}
```

结果 (number):

```json
2017
```

### `$now.zone`

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

```javascript
{{ $now.zone }}
```

结果 (object):

```json
{
  "fixed": 0
}
```

### `$now.zoneName`

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

```javascript
{{ $now.zoneName }}
```

结果 (string):

```json
"UTC"
```

## 转换与格式化

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

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

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

Returns `Duration`.

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

返回此 DateTime 与当前时间之间的差值（Duration）。参见 `DateTime#diff`。

- `unit` (string|string[], optional, default ['milliseconds'): Duration 中要包含的单位或单位数组，例如 `'hours'` 或 `'days'`。
- `opts` (Object): 影响 Duration 创建的选项。
- `opts.conversionAccuracy` (string, optional, default 'casual'): 使用的换算体系。

Returns `Duration`.

### `$now.endOf(unit, opts)`

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

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

Returns `DateTime`.

```javascript
{{ $now.constructor.local(2014, 3, 3).endOf('month').toISO() }}
```

结果 (string):

```json
"2014-03-31T23:59:59.999Z"
```

```javascript
{{ $now.constructor.local(2014, 3, 3).endOf('year').toISO() }}
```

结果 (string):

```json
"2014-12-31T23:59:59.999Z"
```

```javascript
{{ $now.constructor.local(2014, 3, 3).endOf('week').toISO() }}
```

结果 (string):

```json
"2014-03-09T23:59:59.999Z"
```

### `$now.equals(other)`

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

- `other` (DateTime): 另一个 DateTime。

Returns `boolean`.

### `$now.get(unit)`

获取指定单位的值。

- `unit` (string): 单位名称，例如 `'minute'` 或 `'day'`。

Returns `number`.

```javascript
{{ $now.constructor.local(2017, 7, 4).get('month') }}
```

结果 (number):

```json
7
```

```javascript
{{ $now.constructor.local(2017, 7, 4).get('day') }}
```

结果 (number):

```json
4
```

### `$now.getPossibleOffsets()`

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

Returns `DateTime[]`.

```javascript
{{ $now.getPossibleOffsets() }}
```

结果 (list):

```json
[
  "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, optional, default false): 为 `true` 时按 locale 计算周，即使用该 locale 的每周起始日；只使用此 DateTime 的 locale。

Returns `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()` 接受的对象。

Returns `DateTime`.

```javascript
{{ $now.plus(123) }}
```

结果 (DateTime):

```json
"2026-11-26T14:30:00.123Z"
```

```javascript
{{ $now.plus({ minutes: 15 }) }}
```

结果 (DateTime):

```json
"2026-11-26T14:45:00.000Z"
```

```javascript
{{ $now.plus({ days: 1 }) }}
```

结果 (DateTime):

```json
"2026-11-27T14:30:00.000Z"
```

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

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

- `properties` (Object): 要设置的属性。

Returns `DateTime`.

```javascript
{{ $now.constructor.local(2017, 5, 25).reconfigure({ locale: 'en-GB' }) }}
```

结果 (DateTime):

```json
"2017-05-25T00:00:00.000Z"
```

### `$now.resolvedLocaleOptions(opts = {})`

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

- `opts` (Object): 与 `toLocaleString` 相同的选项。

Returns `Object`.

### `$now.set(values)`

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

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

- `values` (Object): 单位到数值的映射对象。

Returns `DateTime`.

### `$now.setLocale(locale)`

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

Returns `DateTime`.

```javascript
{{ $now.constructor.local(2017, 5, 25).setLocale('en-GB') }}
```

结果 (DateTime):

```json
"2017-05-25T00:00:00.000Z"
```

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

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

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

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

Returns `DateTime`.

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

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

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

Returns `DateTime`.

```javascript
{{ $now.constructor.local(2014, 3, 3).startOf('month').toISODate() }}
```

结果 (string):

```json
"2014-03-01"
```

```javascript
{{ $now.constructor.local(2014, 3, 3).startOf('year').toISODate() }}
```

结果 (string):

```json
"2014-01-01"
```

```javascript
{{ $now.constructor.local(2014, 3, 3).startOf('week').toISODate() }}
```

结果 (string):

```json
"2014-03-03"
```

### `$now.toBSON()`

返回与此 DateTime 等价、可被 BSON 序列化的值（JavaScript `Date`）。

Returns `Date`.

```javascript
{{ $now.toBSON() }}
```

结果 (object):

```json
"2026-11-26T14:30:00.000Z"
```

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

按指定的格式字符串返回此 DateTime 的字符串表示。**这未必是你想要的**：更灵活的格式化方式见 `DateTime#toLocaleString`。格式记号（token）及其含义见 [记号表](https://moment.github.io/luxon/#/formatting?id=table-of-tokens)。未指定 locale 时默认使用 en-US，与系统 locale 无关。

- `fmt` (string): 格式字符串。
- `opts` (Object): 用于覆盖此 DateTime 配置选项的 opts。

Returns `string`.

```javascript
{{ $now.toFormat('yyyy LLL dd') }}
```

结果 (string):

```json
"2026 Nov 26"
```

```javascript
{{ $now.setLocale('fr').toFormat('yyyy LLL dd') }}
```

结果 (string):

```json
"2026 nov. 26"
```

```javascript
{{ $now.toFormat('yyyy LLL dd', { locale: "fr" }) }}
```

结果 (string):

```json
"2026 nov. 26"
```

### `$now.toHTTP()`

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

Returns `string`.

```javascript
{{ $now.constructor.utc(2014, 7, 13).toHTTP() }}
```

结果 (string):

```json
"Sun, 13 Jul 2014 00:00:00 GMT"
```

```javascript
{{ $now.constructor.utc(2014, 7, 13, 19).toHTTP() }}
```

结果 (string):

```json
"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, optional, default false): 毫秒为 0 时在输出中省略毫秒。
- `opts.suppressSeconds` (boolean, optional, default false): 秒为 0 时在输出中省略秒。
- `opts.includeOffset` (boolean, optional, default true): 是否包含时区偏移，例如 `Z` 或 `-04:00`。
- `opts.extendedZone` (boolean, optional, default false): 追加时区格式扩展（如 `[America/New_York]`）。
- `opts.format` (string, optional, default 'extended'): 在基本格式（basic）与扩展格式（extended）之间选择。
- `opts.precision` (string, optional, default 'milliseconds'): 把输出截断到指定精度：`'years'`、`'months'`、`'days'`、`'hours'`、`'minutes'`、`'seconds'` 或 `'milliseconds'`。与 `suppressSeconds` 或 `suppressMilliseconds` 同时使用时，`precision` 决定输出显示的最大单位，但秒或毫秒为 0 时仍会被省略。

Returns `string|null`.

```javascript
{{ $now.constructor.utc(1983, 5, 25).toISO() }}
```

结果 (string):

```json
"1983-05-25T00:00:00.000Z"
```

```javascript
{{ $now.toISO() }}
```

结果 (string):

```json
"2026-11-26T14:30:00.000Z"
```

```javascript
{{ $now.toISO({ includeOffset: false }) }}
```

结果 (string):

```json
"2026-11-26T14:30:00.000"
```

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

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

- `opts` (Object): 选项对象。
- `opts.format` (string, optional, default 'extended'): 在基本格式（basic）与扩展格式（extended）之间选择。
- `opts.precision` (string, optional, default 'day'): 把输出截断到指定精度：`'years'`、`'months'` 或 `'days'`。

Returns `string|null`.

```javascript
{{ $now.constructor.utc(1982, 5, 25).toISODate() }}
```

结果 (string):

```json
"1982-05-25"
```

```javascript
{{ $now.constructor.utc(1982, 5, 25).toISODate({ format: 'basic' }) }}
```

结果 (string):

```json
"19820525"
```

```javascript
{{ $now.constructor.utc(1982, 5, 25).toISODate({ precision: 'month' }) }}
```

结果 (string):

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

Returns `string`.

```javascript
{{ $now.constructor.utc().set({ hour: 7, minute: 34 }).toISOTime() }}
```

结果 (string):

```json
"07:34:00.000Z"
```

```javascript
{{ $now.constructor.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) }}
```

结果 (string):

```json
"07:34Z"
```

```javascript
{{ $now.constructor.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) }}
```

结果 (string):

```json
"073400.000Z"
```

### `$now.toISOWeekDate()`

返回此 DateTime 周日期（week date）符合 ISO 8601 的字符串表示，例如 `2026-W48-4`。

Returns `string`.

```javascript
{{ $now.constructor.utc(1982, 5, 25).toISOWeekDate() }}
```

结果 (string):

```json
"1982-W21-2"
```

### `$now.toJSDate()`

返回与此 DateTime 等价的 JavaScript `Date`。

Returns `Date`.

```javascript
{{ $now.toJSDate() }}
```

结果 (object):

```json
"2026-11-26T14:30:00.000Z"
```

### `$now.toJSON()`

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

Returns `string`.

```javascript
{{ $now.toJSON() }}
```

结果 (string):

```json
"2026-11-26T14:30:00.000Z"
```

### `$now.toLocal()`

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

Returns `DateTime`.

```javascript
{{ $now.toLocal() }}
```

结果 (DateTime):

```json
"2026-11-26T14:30:00.000Z"
```

### `$now.toLocaleParts(opts = {})`

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

- `opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`.`: `Intl.DateTimeFormat` 构造函数选项，与 `toLocaleString` 相同。

```javascript
{{ $now.toLocaleParts() }}
```

结果 (list):

```json
[
  {
    "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。

Returns `string`.

```javascript
{{ $now.toLocaleString() }}
```

结果 (string):

```json
"11/26/2026"
```

```javascript
{{ $now.setLocale('en-gb').toLocaleString() }}
```

结果 (string):

```json
"26/11/2026"
```

```javascript
{{ $now.toLocaleString($now.constructor.DATE_FULL) }}
```

结果 (string):

```json
"November 26, 2026"
```

### `$now.toMillis()`

返回此 DateTime 的纪元毫秒数（epoch milliseconds）。

Returns `number`.

```javascript
{{ $now.toMillis() }}
```

结果 (number):

```json
1795703400000
```

### `$now.toObject(opts = {})`

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

- `opts - options for generating the object`: 生成对象时使用的选项。
- `opts.includeConfig` (boolean, optional, default false): 是否在输出中包含配置属性（locale、numberingSystem、outputCalendar）。

Returns `Object`.

```javascript
{{ $now.toObject() }}
```

结果 (object):

```json
{
  "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, optional, default DateTime.now()): 作为比较基准的 DateTime，默认为当前时间。
- `options.style` (string, optional, default "long"): 单位的样式，必须为 `"long"`、`"short"` 或 `"narrow"`。
- `options.unit` (string|string[]): 使用指定的单位或单位数组；省略或传入数组时，方法会自动选择最合适的单位。可传数组，或 `"years"`、`"quarters"`、`"months"`、`"weeks"`、`"days"`、`"hours"`、`"minutes"`、`"seconds"` 之一。
- `options.round` (boolean, optional, default true): 是否对输出中的数字取整。
- `options.rounding` (string, optional, default "trunc"): 对输出数字取整时使用的方法：`"trunc"`（向零）、`"expand"`（远离零）、`"round"`、`"floor"` 或 `"ceil"`。
- `options.padding` (number, optional, default 0): 以毫秒计的填充量；结果落在该阈值内时向上取整。不要与 `{round: false}` 同时使用，否则小数输出会包含这部分填充。
- `options.locale` (string): 覆盖此 DateTime 的 locale。
- `options.numberingSystem` (string): 覆盖此 DateTime 的 numberingSystem；Intl 可能不予采纳。

```javascript
{{ $now.plus({ days: 1 }).toRelative() }}
```

结果 (string):

```json
"in 1 day"
```

```javascript
{{ $now.setLocale("es").toRelative({ days: 1 }) }}
```

结果 (string):

```json
"dentro de 0 segundos"
```

```javascript
{{ $now.plus({ days: 1 }).toRelative({ locale: "fr" }) }}
```

结果 (string):

```json
"dans 1 jour"
```

### `$now.toRelativeCalendar(options = {})`

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

- `options` (Object): 影响输出结果的选项。
- `options.base` (DateTime, optional, default DateTime.now()): 作为比较基准的 DateTime，默认为当前时间。
- `options.locale` (string): 覆盖此 DateTime 的 locale。
- `options.unit` (string): 使用指定的单位；省略时由方法自动选择。可为 `"years"`、`"quarters"`、`"months"`、`"weeks"` 或 `"days"` 之一。
- `options.numberingSystem` (string): 覆盖此 DateTime 的 numberingSystem；Intl 可能不予采纳。

```javascript
{{ $now.plus({ days: 1 }).toRelativeCalendar() }}
```

结果 (string):

```json
"tomorrow"
```

```javascript
{{ $now.setLocale("es").plus({ days: 1 }).toRelative() }}
```

结果 (string):

```json
"dentro de 1 día"
```

```javascript
{{ $now.plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) }}
```

结果 (string):

```json
"demain"
```

### `$now.toRFC2822()`

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

Returns `string`.

```javascript
{{ $now.constructor.utc(2014, 7, 13).toRFC2822() }}
```

结果 (string):

```json
"Sun, 13 Jul 2014 00:00:00 +0000"
```

```javascript
{{ $now.constructor.local(2014, 7, 13).toRFC2822() }}
```

结果 (string):

```json
"Sun, 13 Jul 2014 00:00:00 +0000"
```

### `$now.toSeconds()`

返回此 DateTime 的纪元秒数（小数部分为毫秒）。

Returns `number`.

```javascript
{{ $now.toSeconds() }}
```

结果 (number):

```json
1795703400
```

### `$now.toSQL(opts = {})`

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

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

Returns `string`.

```javascript
{{ $now.constructor.utc(2014, 7, 13).toSQL() }}
```

结果 (string):

```json
"2014-07-13 00:00:00.000 Z"
```

```javascript
{{ $now.constructor.local(2014, 7, 13).toSQL() }}
```

结果 (string):

```json
"2014-07-13 00:00:00.000 Z"
```

```javascript
{{ $now.constructor.local(2014, 7, 13).toSQL({ includeOffset: false }) }}
```

结果 (string):

```json
"2014-07-13 00:00:00.000"
```

### `$now.toSQLDate()`

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

Returns `string|null`.

```javascript
{{ $now.constructor.utc(2014, 7, 13).toSQLDate() }}
```

结果 (string):

```json
"2014-07-13"
```

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

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

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

Returns `string`.

```javascript
{{ $now.constructor.utc().toSQL() }}
```

结果 (string):

```json
"2026-11-26 14:30:00.000 Z"
```

```javascript
{{ $now.toSQL() }}
```

结果 (string):

```json
"2026-11-26 14:30:00.000 Z"
```

```javascript
{{ $now.toSQL({ includeOffset: false }) }}
```

结果 (string):

```json
"2026-11-26 14:30:00.000"
```

### `$now.toString()`

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

Returns `string`.

```javascript
{{ $now.toString() }}
```

结果 (string):

```json
"2026-11-26T14:30:00.000Z"
```

### `$now.toUnixInteger()`

返回此 DateTime 的纪元秒数（取整）。

Returns `number`.

```javascript
{{ $now.toUnixInteger() }}
```

结果 (number):

```json
1795703400
```

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

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

- `offset` (number, optional, default 0): 可选，相对 UTC 的偏移分钟数。
- `opts` (Object, optional, default {}): 传给 `setZone()` 的选项。

Returns `DateTime`.

```javascript
{{ $now.toUTC() }}
```

结果 (DateTime):

```json
"2026-11-26T14:30:00.000Z"
```

### `$now.until(otherDateTime)`

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

- `otherDateTime` (DateTime): Interval 的另一个端点。

Returns `Interval|DateTime`.

### `$now.valueOf()`

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

Returns `number`.

```javascript
{{ $now.valueOf() }}
```

结果 (number):

```json
1795703400000
```
