- 564
Retrieve Local Datetime in n8n Using Moment.js Function Node
Learn to retrieve local datetime using Moment.js in n8n. Enhance workflows with precise time handling and seamless integration.
Learn to retrieve local datetime using Moment.js in n8n. Enhance workflows with precise time handling and seamless integration.
Who is this workflow for? This guide demonstrates how to retrieve the local date and time within an n8n Function node using the Moment.js library. By configuring the environment correctly, you can seamlessly integrate local time data into your automated workflows..
GENERIC_TIMEZONE
environment variable to your desired timezone.NODE_FUNCTION_ALLOW_EXTERNAL=moment
.const moment = require('moment');
to include the library.javascript let date = moment().tz($env['GENERIC_TIMEZONE']);
javascript let year = date.year(); let month = date.month(); // zero-indexed let day = date.date(); let hour = date.hours(); let minute = date.minutes(); let second = date.seconds(); let millisecond = date.millisecond();
javascript let formatted = date.format('YYYY-MM-DD HH:mm:ss.SSS Z');
javascript return [ { json: { utc: date, year: year, month: month, day: day, hour: hour, minute: minute, second: second, millisecond: millisecond, formatted: formatted } } ];
This workflow is ideal for developers and automation enthusiasts who need to incorporate localized date and time information into their n8n workflows. It is particularly useful for those managing workflows that operate across different time zones.
This workflow provides a straightforward method to obtain and utilize local date and time within an n8n Function node using Moment.js. By correctly setting up environment variables and leveraging Moment.js, you can enhance your automated workflows with precise and localized time data.
Streamline your Reddit summaries using AI. Automate post curation and content analysis with this efficient n8n workflow template.
Streamline workflows by integrating Notion and Asana. Automate task synchronization and enhance productivity with this efficient n8n solution.
Streamline scheduling by automating Pipedrive activities with key features like seamless integration and real-time updates from Calendly events.
Help us find the best n8n templates
A curated directory of the best n8n templates for workflow automations.