Skip to content

日期和时间(Date & Time)#

日期和时间节点会处理日期和时间数据并将其转换为不同的格式。

🌐 The Date & Time node manipulates date and time data and convert it to different formats.

Timezone settings

The node relies on the timezone setting. n8n uses either:

  1. The workflow timezone, if set. Refer to Workflow settings for more information.
  2. The n8n instance timezone, if the workflow timezone isn't set. The default is America/New York for self-hosted instances. n8n Cloud tries to detect the instance owner's timezone when they sign up, falling back to GMT as the default. Self-hosted users can change the instance setting using Environment variables. Cloud admins can change the instance timezone in the Admin dashboard.

其他节点的日期和时间

您可以在 Code 节点中以及任何节点的表达式中处理日期和时间。n8n 支持 Luxon,以帮助在 JavaScript 中处理日期和时间。更多信息请参阅 使用 Luxon 的日期和时间

操作(Operations)#

  • 添加到日期:向日期添加指定的时间量。
  • 提取日期的部分内容:提取日期的某一部分,例如年份、月份或日期。
  • 格式化日期:使用预设选项或自定义表达式将日期的格式转换为新格式。
  • 获取当前日期:获取当前日期,并选择是否包含当前时间。适用于触发其他流程和条件逻辑。
  • 计算日期之间的时间:计算两个日期之间以特定单位表示的时间量。
  • 四舍五入日期:将日期向上或向下四舍五入到你选择的最接近单位,例如月份、天或小时。
  • 从日期中减去:从一个日期中减去指定的时间量。

有关每个操作的特定参数和选项,请参阅以下章节。

🌐 Refer to the sections below for parameters and options specific to each operation.

添加到日期(Add to a Date)#

使用以下参数配置此操作的节点:

🌐 Configure the node for this operation using these parameters:

  • 要添加的日期:输入你想要更改的日期。
  • 添加时间单位:为持续时间参数选择时间单位。
  • 持续时间:输入要添加到日期的时间单位数量。
  • 输出字段名称:输入要输出新日期的字段名称。

添加日期选项(Add to a Date options)#

此操作有一个选项:包含输入字段。如果你希望在输出中包含所有输入字段,请打开此选项。如果关闭,则仅输出输出字段名称及其内容。

🌐 This operation has one option: Include Input Fields. If you'd like to include all of the input fields in the output, turn this option on. If turned off, only the Output Field Name and its contents are output.

提取日期的一部分(Extract Part of a Date)#

使用以下参数配置此操作的节点:

🌐 Configure the node for this operation using these parameters:

  • 日期:输入你想要四舍五入或提取部分的日期。
  • 部分:选择你要提取的日期部分。可选择:
    • 小时
    • 分钟
    • 第二
  • 输出字段名称:输入要输出提取日期部分的字段名称。

提取日期的一部分选项(Extract Part of a Date options)#

此操作有一个选项:包含输入字段。如果你希望在输出中包含所有输入字段,请打开此选项。如果关闭,则仅输出输出字段名称及其内容。

🌐 This operation has one option: Include Input Fields. If you'd like to include all of the input fields in the output, turn this option on. If turned off, only the Output Field Name and its contents are output.

格式化日期(Format a Date)#

使用以下参数配置此操作的节点:

🌐 Configure the node for this operation using these parameters:

  • 日期:输入你想要格式化的日期。
  • 格式:选择你要将日期更改为的格式。可选择如下:
    • 自定义格式:使用 Luxon 的 特殊标记 输入你自己的自定义格式。标记区分大小写。
    • MM/DD/YYYY:对于 4 September 1986,这会将日期格式化为 09/04/1986
    • YYYY/MM/DD:对于 4 September 1986,这将日期格式化为 1986/09/04
    • MMMM DD YYYY:对于 4 September 1986,这会将日期格式化为 September 04 1986
    • MM-DD-YYYY:对于 4 September 1986,此格式将日期显示为 09-04-1986
    • YYYY-MM-DD:对于 4 September 1986,这将日期格式化为 1986-09-04
  • 输出字段名称:输入要将格式化日期输出到的字段名称。

格式化日期选项(Format a Date options)#

此操作包含以下选项:

🌐 This operation includes these options:

  • 包含输入字段:如果你希望在输出中包含所有输入字段,请开启此选项。关闭后,仅输出输出字段名称及其内容。
  • 日期格式:如果节点未能正确识别日期格式,请在此输入该日期的格式,以便节点能够正确处理。使用 Luxon 的 特殊标记 输入格式。标记区分大小写
  • 使用工作流时区:是使用输入的时区(关闭)还是工作流的时区(开启)。

获取当前日期(Get Current Date)#

使用以下参数配置此操作的节点:

🌐 Configure the node for this operation using these parameters:

  • 包括当前时间:选择是包含当前时间(开启)还是将时间设置为午夜(关闭)。
  • 输出字段名称:输入要输出当前日期的字段名称。

获取当前日期选项(Get Current Date options)#

此操作包含以下选项:

🌐 This operation includes these options:

  • 包含输入字段:如果你希望在输出中包含所有输入字段,请开启此选项。关闭后,仅输出输出字段名称及其内容。
  • 时区:设置要使用的时区。如果留空,节点将使用 n8n 实例的时区。

+00:00 时区

使用 GMT 表示 +00:00 时区。

获取日期之间的时间间隔(Get Time Between Dates)#

使用以下参数配置此操作的节点:

🌐 Configure the node for this operation using these parameters:

  • 开始日期:输入你想比较的较早日期。
  • 结束日期:输入你想比较的较晚日期。
  • 单位:选择你想要计算时间间隔的单位。你可以包含多个单位。可选择以下单位:
    • 小时
    • 分钟
    • 第二
    • 毫秒
  • 输出字段名称:输入要输出两者间计算时间的字段名称。

获取日期之间的时间间隔选项(Get Time Between Dates options)#

“获取日期之间的时间”操作包括 包括输入字段 选项以及 输出为 ISO 字符串 选项。如果你关闭此选项,每个你选择的单位都会返回其各自的时间差计算,例如:

🌐 The Get Time Between Dates operation includes the Include Input Fields option as well as an Output as ISO String option. If you leave this option off, each unit you selected will return its own time difference calculation, for example:

1
2
3
4
时间差
年 : 1
月 : 3
日 : 13

如果你打开 以 ISO 字符串输出 选项,节点会将输出格式化为单个 ISO 持续时间字符串,例如:P1Y3M13D

🌐 If you turn on the Output as ISO String option, the node formats the output as a single ISO duration string, for example: P1Y3M13D.

ISO 持续时间格式显示为 P<n>Y<n>M<n>DT<n>H<n>M<n>S<n> 是其后单位的数字。

  • P = 周期(持续时间)。它用于所有 ISO 持续时间字符串的开头。
  • Y = 年
  • M = 个月
  • W = 周
  • D = 天
  • T = 日期和时间之间的分隔符,用于避免月份和分钟之间的混淆。
  • H = 小时
  • M = 分钟
  • S = 秒

毫秒没有独立的单位,而是作为秒的小数部分。例如,2.1毫秒是 0.0021S

🌐 Milliseconds don't get their own unit, but instead are decimal seconds. For example, 2.1 milliseconds is 0.0021S.

日期取整(Round a Date)#

使用以下参数配置此操作的节点:

🌐 Configure the node for this operation using these parameters:

  • 日期:输入你想要取整的日期。
  • 模式:选择是向下取整还是向上取整
  • 四舍五入到最接近的:选择你想要四舍五入到的单位。可选择:
    • 小时
    • 分钟
    • 第二
  • 输出字段名称:输入要输出四舍五入日期的字段名称。

日期取整选项(Round a Date options)#

此操作有一个选项:包含输入字段。如果你希望在输出中包含所有输入字段,请打开此选项。如果关闭,则仅输出输出字段名称及其内容。

🌐 This operation has one option: Include Input Fields. If you'd like to include all of the input fields in the output, turn this option on. If turned off, only the Output Field Name and its contents are output.

日期减法(Subtract From a Date)#

使用以下参数配置此操作的节点:

🌐 Configure the node for this operation using these parameters:

  • 要减去的日期:输入你想从中减去的日期。
  • 要减去的时间单位:选择要减去的持续时间的单位。
  • 持续时间:输入你想从要减去的日期中减去的时间单位数量。
  • 输出字段名称:输入要输出四舍五入日期的字段名称。

日期减法选项(Subtract From a Date options)#

此操作有一个选项:包含输入字段。如果你希望在输出中包含所有输入字段,请打开此选项。如果关闭,则仅输出输出字段名称及其内容。

🌐 This operation has one option: Include Input Fields. If you'd like to include all of the input fields in the output, turn this option on. If turned off, only the Output Field Name and its contents are output.

模板和示例(Templates and examples)#

Template widget placeholder.

日期和时间节点使用 Luxon。你也可以在 代码 节点和 表达式 中使用 Luxon。更多信息请参考 使用 Luxon 的日期和时间

🌐 The Date & Time node uses Luxon. You can also use Luxon in the Code node and expressions. Refer to Date and time with Luxon for more information.

支持的日期格式(Supported date formats)#

n8n 支持所有 Luxon 支持的 日期格式。标记区分大小写。

🌐 n8n supports all date formats supported by Luxon. Tokens are case-sensitive.