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.

Date and time in other nodes

你可以在“代码”节点以及任何节点的表达式中使用数据和时间。n8n 支持 Luxon,以便在 JavaScript 中处理日期和时间。有关更多信息,请参阅 使用 Luxon 处理日期和时间

¥You can work with data and time in the Code node, and in expressions in any node. n8n supports Luxon to help work with date and time in JavaScript. Refer to Date and time with Luxon for more information.

操作#

¥Operations

  • 添加到日期:为日期添加指定时间。

¥Add to a Date: Add a specified amount of time to a date.

  • 提取日期的一部分:提取部分日期,例如年、月或日。

¥Extract Part of a Date: Extract part of a date, such as the year, month, or day.

  • 格式化日期:使用预设选项或自定义表达式将日期格式转换为新格式。

¥Format a Date: Transform a date's format to a new format using preset options or a custom expression.

  • 获取当前日期获取当前日期,并选择是否包含当前时间。可用于触发其他流程和条件逻辑。

¥Get Current Date: Get the current date and choose whether to include the current time or not. Useful for triggering other flows and conditional logic.

  • 获取日期之间的时间间隔计算两个日期之间的特定时间单位。

¥Get Time Between Dates: Calculate the amount of time in specific units between two dates.

  • 四舍五入日期:将日期向上或向下取整到你选择的最接近的单位,例如月、日或小时。

¥Round a Date: Round a date up or down to the nearest unit of your choice, such as month, day, or hour.

  • 从日期中减去:从日期中减去指定的时间。

¥Subtract From a Date: Subtract a specified amount of time from a date.

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

¥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:

  • 要添加到的日期:输入要更改的日期。

¥Date to Add To: Enter the date you want to change.

  • 要添加的时间单位:选择“持续时间”参数的时间单位。

¥Time Unit to Add: Select the time unit for the Duration parameter.

  • 持续时间:输入要添加到日期的时间单位数。

¥Duration: Enter the number of time units to add to the date.

  • 输出字段名称:输入用于输出新日期的字段名称。

¥Output Field Name: Enter the name of the field to output the new date to.

添加日期选项#

¥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:

  • 日期:输入要四舍五入或提取部分内容的日期。

¥Date: Enter the date you want to round or extract part of.

  • 部分:选择要提取的数据部分。选择以下选项:

¥Part: Select the part of the date you want to extract. Choose from:

  • ¥Year

  • ¥Month

  • ¥Week

  • ¥Day

  • 小时

    ¥Hour

  • 分钟

    ¥Minute

  • ¥Second

  • 输出字段名称:输入用于输出提取出的日期部分的字段名称。

¥Output Field Name: Enter the name of the field to output the extracted date part to.

提取日期的一部分选项#

¥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:

  • 日期:输入要格式化的日期。

¥Date: Enter the date you want to format.

  • 格式:选择日期格式。选择以下选项:

¥Format: Select the format you want to change the date to. Choose from:

  • 自定义格式:使用 Luxon 的 特殊令牌 输入你自己的自定义格式。令牌区分大小写。

    ¥Custom Format: Enter your own custom format using Luxon's special tokens. Tokens are case-sensitive.

  • MM/DD/YYYY:对于 4 September 1986,此设置会将日期格式化为 09/04/1986

    ¥MM/DD/YYYY: For 4 September 1986, this formats the date as 09/04/1986.

  • YYYY/MM/DD:对于 4 September 1986,此设置会将日期格式化为 1986/09/04

    ¥YYYY/MM/DD: For 4 September 1986, this formats the date as 1986/09/04.

  • MMMM DD YYYY:对于 4 September 1986,此设置会将日期格式化为 September 04 1986

    ¥MMMM DD YYYY: For 4 September 1986, this formats the date as September 04 1986.

  • MM-DD-YYYY:对于 4 September 1986,此设置会将日期格式化为 09-04-1986

    ¥MM-DD-YYYY: For 4 September 1986, this formats the date as 09-04-1986.

  • YYYY-MM-DD:对于 4 September 1986,此设置会将日期格式化为 1986-09-04

    ¥YYYY-MM-DD: For 4 September 1986, this formats the date as 1986-09-04.

  • 输出字段名称:输入用于输出格式化日期的字段名称。

¥Output Field Name: Enter the name of the field to output the formatted date to.

格式化日期选项#

¥Format a Date options

此操作包含以下选项:

¥This operation includes these options:

  • 包含输入字段:如果你希望将所有输​​入字段都包含在输出中,请启用此选项。如果关闭此选项,则仅输出“输出字段名称”及其内容。

¥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.

  • 从日期格式获取:如果节点无法正确识别日期格式,请在此处输入该日期的格式,以便节点能够正确处理。使用 Luxon 的 特殊令牌 输入格式。令牌区分大小写

¥From Date Format: If the node isn't recognizing the Date format correctly, enter the format for that Date here so the node can process it properly. Use Luxon's special tokens to enter the format. Tokens are case-sensitive

  • 使用工作流时区:是否使用输入时区(已关闭)或工作流时区(已开启)。

¥Use Workflow Timezone: Whether to use the input's time zone (turned off) or the workflow's timezone (turned on).

获取当前日期#

¥Get Current Date

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

¥Configure the node for this operation using these parameters:

  • 包含当前时间:选择是否包含当前时间(已开启)或将时间设置为午夜(已关闭)。

¥Include Current Time: Choose whether to include the current time (turned on) or to set the time to midnight (turned off).

  • 输出字段名称:输入用于输出当前日期的字段名称。

¥Output Field Name: Enter the name of the field to output the current date to.

获取当前日期选项#

¥Get Current Date options

此操作包含以下选项:

¥This operation includes these options:

  • 包含输入字段:如果你希望将所有输​​入字段都包含在输出中,请启用此选项。如果关闭此选项,则仅输出“输出字段名称”及其内容。

¥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.

  • 时区:设置要使用的时区。如果留空,节点将使用 n8n 实例的时区。

¥Timezone: Set the timezone to use. If left blank, the node uses the n8n instance's timezone.

+00:00 timezone

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

¥Use GMT for +00:00 timezone.

获取日期之间的时间间隔#

¥Get Time Between Dates

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

¥Configure the node for this operation using these parameters:

  • 开始日期:请输入要比较的较早日期。

¥Start Date: Enter the earlier date you want to compare.

  • 结束日期:输入要比较的较晚日期。

¥End Date: Enter the later date you want to compare.

  • 单位:选择要计算时间间隔的单位。你可以包含多个单元。选择以下选项:

¥Units: Select the units you want to calculate the time between. You can include multiple units. Choose from:

  • ¥Year

  • ¥Month

  • ¥Week

  • ¥Day

  • 小时

    ¥Hour

  • 分钟

    ¥Minute

  • ¥Second

  • 毫秒

    ¥Millisecond

  • 输出字段名称:输入用于输出计算出的时间间隔的字段名称。

¥Output Field Name: Enter the name of the field to output the calculated time between to.

获取日期之间的时间间隔选项#

¥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
timeDifference
years : 1
months : 3
days : 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> 是其后单元的编号。

¥ISO duration format displays a format as P<n>Y<n>M<n>DT<n>H<n>M<n>S. <n> is the number for the unit after it.

  • P = 周期(持续时间)。它会为所有 ISO 持续时间字符串命名。

¥P = period (duration). It begins all ISO duration strings.

  • Y = 年

¥Y = years

  • M = 个月

¥M = months

  • W = 周

¥W = weeks

  • D = 天

¥D = days

  • T = 日期和时间之间的分隔符,用于避免月份和分钟之间的混淆。

¥T = delineator between dates and times, used to avoid confusion between months and minutes

  • H = 小时

¥H = hours

  • M = 分钟

¥M = minutes

  • S = 秒

¥S = seconds

毫秒没有自己的单位,而是以十进制秒表示。例如,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:

  • 日期:输入要四舍五入的日期。

¥Date: Enter the date you'd like to round.

  • 模式:选择向下取整还是向上取整。

¥Mode: Choose whether to Round Down or Round Up.

  • 发送至最近的邮箱:选择要四舍五入到的单位。选择以下选项:

¥To Nearest: Select the unit you'd like to round to. Choose from:

  • ¥Year

  • ¥Month

  • ¥Week

  • ¥Day

  • 小时

    ¥Hour

  • 分钟

    ¥Minute

  • ¥Second

  • 输出字段名称:输入用于输出四舍五入后的日期的字段名称。

¥Output Field Name: Enter the name of the field to output the rounded date to.

日期取整选项#

¥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:

  • 要从中减去的日期:输入要从中减去的日期。

¥Date to Subtract From: Enter the date you'd like to subtract from.

  • 要减去的时间单位:选择要减去的持续时间的单位。

¥Time Unit to Subtract: Select the unit for the Duration amount you want to subtract.

  • 持续时间:输入要从“要减去的日期”中减去的时间单位数。

¥Duration: Enter the amount of the time units you want to subtract from the Date to Subtract From.

  • 输出字段名称:输入用于输出四舍五入后的日期的字段名称。

¥Output Field Name: Enter the name of the field to output the rounded date to.

日期减法选项#

¥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.

相关资源#

¥Related resources

日期和时间节点使用 Luxon。你还可以在 代码 节点和 expressions 中使用 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.