- 589
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.
Simplify task management by automating Asana task creation with n8n. Enhance productivity with seamless integration and real-time updates.
Streamline workflows by generating AI images and storing them in Google Drive with Fal.ai integration, enhancing efficiency and creativity.
Automate tracking changes in Google Sheets with n8n. Benefit from timely updates every 45 minutes and streamline your workflow efficiently.
Help us find the best n8n templates
A curated directory of the best n8n templates for workflow automations.