- 609
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.
Enhance customer insights by integrating Qdrant with Python in n8n. Streamline data processing and gain valuable insights effortlessly.
Streamline data extraction with ease. Automatically extract first and last names from Facebook using this n8n template's seamless integration.
Implement real-time toxic language detection in Telegram with this n8n template. Enhance chat safety using automated monitoring and alert features.
Help us find the best n8n templates
A curated directory of the best n8n templates for workflow automations.