Different Timezone in Set Node

I have a workflow to sent the current time, in my timezone with the Set node. The issue I’m getting is that the time in the Set Node and the one in the Workflow and n8n env setting are different.

Here is an example workflow:

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "timeNow",
              "value": "={{ new Date(new Date().getTime()) }}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        720,
        360
      ]
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        460,
        360
      ]
    }
  ],
  "connections": {
    "Cron": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

If I check the time in the set node in the executions history, it’s different from the one I need. Any help on this?

Thanks.

Hi @zocket, I am not sure I see the actual difference from looking at your workflow.

I’ve activated your workflow with a time zone setting of Europe/Berlin. It ran at 10:23 Berlin time which is 9:23 UTC. The Set node returned the right time for me when looking at its execution (the Z appended to the String indicates Zulu time which is equal to UTC time):

image

Or were you looking to get a string representation of your local time zone? If so, you could use toLocaleDateString() or toLocaleTimeString(). For example, to get the current time in New York, I could use an expression like:

{{new Date().toLocaleTimeString('en-US', {timeZone: 'America/New_York'}) }}

Hey @zocket,

Have you set the TZ environment variable? I found on my instances I have to set that and GENERIC_TIMEZONE to get the right time.