n8n Workflow

Get Local Datetime Into Function Node Using Moment Js

This n8n workflow retrieves tasks and integrates with various services. Get Local Datetime Into Function Node Using Moment Js - ready to import and run in your n8n instance.

n8n workflow.json

About This Script

This n8n workflow retrieves tasks and integrates with various services. Get Local Datetime Into Function Node Using Moment Js - ready to import and run in your n8n instance.
Features:
  • Custom JavaScript function processing
  • Retrieves data from external sources
Source Code
{
    "nodes": [
        {
            "name": "On clicking 'execute'",
            "type": "n8n-nodes-base.manualTrigger",
            "position": [
                250,
                300
            ],
            "parameters": [],
            "typeVersion": 1,
            "id": "b3655bd8-b6e6-4dc3-acc6-adbfdf9eaa8b"
        },
        {
            "name": "Get Local Datetime",
            "type": "n8n-nodes-base.function",
            "position": [
                450,
                300
            ],
            "parameters": {
                "functionCode": "const moment = require('moment');\n\nlet date = moment().tz($env['GENERIC_TIMEZONE']);\n\nlet year = date.year();\nlet month = date.month(); // zero-indexed!\nlet day = date.date();\nlet hour = date.hours();\nlet minute = date.minutes();\nlet second = date.seconds();\nlet millisecond = date.millisecond();\nlet formatted = date.format('YYYY-MM-DD HH:mm:ss.SSS Z');\n\nreturn [\n  {\n    json: {\n      utc: date,\n      year: year,\n      month: month, // zero-indexed!\n      day: day,\n      hour: hour,\n      minute: minute,\n      second: second,\n      millisecond: millisecond,\n      formatted: formatted\n    }\n  }\n];\n"
            },
            "typeVersion": 1,
            "id": "e842b971-ccd8-4ef4-8708-e7aad8c835e4"
        }
    ],
    "connections": {
        "On clicking 'execute'": {
            "main": [
                [
                    {
                        "node": "Get Local Datetime",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    },
    "n8n_version": "1.5.0"
}
Requirements
n8n instance, API credentials for connected services
Tags
#n8n #automation #workflow
Quick Actions
More in n8n Workflows