⚒️ Unix timestamp to ISO date converter

739 views · ⚒️ Engineering

Description

This n8n workflow provides a simple yet powerful utility to convert Unix timestamps (seconds since epoch) into the universally recognized ISO 8601 date and time format. This is crucial for harmonizing date data across different systems, databases, and applications.


🔧 How it works


👤 Who is it for?

This workflow is extremely useful for:


📑 Data Structure

When you trigger the webhook, send a POST request with a JSON body structured as follows:

{
  "timestamp": 1678886400
}

The workflow will return a JSON response similar to this:

{
  "convertedTime": "2023-03-15T00:00:00.000Z"
}

⚙️ Setup Instructions


📝 Tips

This simple conversion workflow can be drastically enhanced and leveraged in many ways:

const date = new Date($json.timestamp * 1000);
const format = $json.format || 'iso'; // Default to ISO
let output;

switch (format.toLowerCase()) {
    case 'iso':
        output = date.toISOString();
        break;
    case 'locale': // e.g., "3/15/2023, 12:00:00 AM UTC"
        output = date.toLocaleString('en-US', { timeZone: 'UTC' });
        break;
    case 'dateonly': // e.g., "2023-03-15"
        output = date.toISOString().split('T')[0];
        break;
    case 'timeonly': // e.g., "00:00:00 UTC"
        output = date.toLocaleTimeString('en-US', { timeZone: 'UTC', hour12: false });
        break;
    default:
        output = date.toISOString(); // Fallback
}
return [{ json: { convertedTime: output } }];

This workflow is a cornerstone for any automation involving diverse date and time data. By implementing the suggested upgrades, you can transform it from a basic converter into a highly flexible and reliable date-time processing hub.

🔗 Nodes Used

Webhook

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup