Date & Time
当前时刻与今天,均为 Luxon DateTime 值。
每个示例都在已部署的表达式引擎上、基于页面末尾的示例上下文运行过。
$now
一个 Luxon DateTime,在节点开始解析其配置时取值:同一节点的所有表达式看到的是同一时刻。它采用服务器时区,因此在格式化或比较日历日期前,请先设置所需时区。
在纯字段中,$now 保留其类型,节点收到的是 DateTime;在混合字段中,它以带引号的 JSON 文本插入。只要结果要写入文本,就请自行格式化(toISO()、toFormat(…))。
成员
| 签名 | 类型 | 说明 |
|---|---|---|
$now.toISO() | string | 带时区偏移的 ISO 8601 日期时间。 |
$now.toISODate() | string | 仅日期:yyyy-MM-dd。 |
$now.toFormat(format) | string | 使用 Luxon 标记的文本:yyyy 年、LL 月、dd 日、HH 时、mm 分、ss 秒。 |
$now.toMillis() | number | 自 1970-01-01 UTC 起的毫秒数。 |
$now.toSeconds() | number | 自 1970-01-01 UTC 起的秒数,含小数。 |
$now.setZone(zone) | DateTime | 同一时刻在另一个 IANA 时区中的表示,例如 America/Bogota 或 UTC。 |
$now.plus({ days, hours, minutes… }) | DateTime | 之后的某个时刻。 |
$now.minus({ days, hours, minutes… }) | DateTime | 之前的某个时刻。 |
$now.startOf(unit) | DateTime | year、month、week、day、hour 或 minute 的起始时刻。 |
$now.endOf(unit) | DateTime | 该单位的最后一毫秒。 |
$now.diff(other, unit) | Duration | 两个日期之间的时长;用 .as('days') 或 .toObject() 读取。 |
$now.weekday | number | 星期几,1(星期一)到 7(星期日)。另有 year、month、day、hour、minute。 |
$now.constructor | DateTime class | DateTime 类本身,用于解析日期:$now.constructor.fromISO(text)、.fromFormat(text, format)、.fromMillis(ms)。 |
示例
距某个以 ISO 文本传入的日期已过去的小时数。
波哥大现在是周末吗?
混合字段中未格式化的 $now 会以带引号的 JSON 插入。
说明
- DateTime 的全部方法、getter 和静态构造函数见 Luxon 参考。
DateTime不是全局名称:请通过$now.constructor获取该类。
在 JSONata 中 不可用:$$now 以对象形式传入,JSONata 无法调用其方法。请使用 JSONata 函数 $now() 和 $fromMillis()。
$today
服务器时区中当天的午夜:$now.startOf('day')。要获取另一时区中当天的起始时刻,请使用 $now.setZone(zone).startOf('day');转换 $today 得到的是服务器当天的午夜在该时区下的表示。
示例
从今天起 30 天后的到期日。
另一时区中今天的起始时刻。
在 JSONata 中 无法在 JSONata 中使用,原因与 $now 相同。
示例上下文
示例基于以下数据运行:当前节点的输入($json)、已运行的节点($(…))、本次运行的 ID 以及当前节点。时钟固定为 2026-11-26T14:30:00.000Z,服务器时区为 UTC,因此各页面中 $now 与 $today 的值都相同。
{
"$json": {
"body": {
"order_id": "ord_1042",
"email": "ana.perez@example.com",
"customer": {
"name": "Ana Pérez",
"segment": "gold"
},
"priority": "",
"items": [
{
"sku": "A-100",
"qty": 2,
"price": 10.5
},
{
"sku": "B-200",
"qty": 0,
"price": 4
},
{
"sku": "C-300",
"qty": 1,
"price": 25
}
],
"tags": [
"new",
"web",
"new"
],
"created_at": "2026-11-25T09:15:00Z"
},
"headers": {
"content-type": "application/json"
},
"query": {},
"method": "POST"
}
}{
"Webhook Receiver": "= $json",
"Normalize input": {
"correlation_id": "c-7f3a",
"channel": "web"
},
"Classify": {
"label": "billing",
"confidence": 0.92
}
}{
"$execution": {
"id": "fir-xxxx",
"flow_instance_id": "fi-xxxx",
"flow_definition_id": "fd-xxxx",
"flow_version_id": "fv-xxxx",
"flow_slug": "order-intake"
},
"$node": {
"id": "node-notify",
"label": "Notify customer"
}
} 示例运行所基于的编排器提交 31e874b