Hey everyone! I’m having a weird problem with date formatting in Zapier’s NodeJS environment. I’m trying to convert some timestamps to US Eastern Time, but it’s not working as expected.
Here’s a simplified version of what I’m doing:
const input = '2023-05-15T10:30:00Z';
const date = new Date(input);
const formatted = date.toLocaleString('en-US', {
timeZone: 'America/New_York',
hour12: true
});
console.log(formatted);
This code works fine elsewhere, but in Zapier, it’s not applying the timezone conversion. The output is still in UTC. No errors, just wrong results.
Has anyone run into this before? Any ideas on how to fix it or work around it? I’m stumped!
hey sofiap, zapier can be tricky with dates. i ran into this too. have you tried using the ‘moment’ library? it’s already there in zapier. just do something like:
const moment = require(‘moment-timezone’);
const formatted = moment(input).tz(‘America/New_York’).format(‘YYYY-MM-DD hh:mm A’);
this worked for me. hope it helps!
I’ve dealt with this exact issue in Zapier before. The problem lies in how Zapier’s NodeJS environment handles certain JavaScript methods. Instead of relying on toLocaleString()
, which seems unreliable in this context, I’ve had success using the Intl.DateTimeFormat
API. Here’s a snippet that should work:
const input = '2023-05-15T10:30:00Z';
const date = new Date(input);
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true
});
const formatted = formatter.format(date);
console.log(formatted);
This approach bypasses the issues with toLocaleString()
and should correctly apply the timezone conversion in Zapier’s environment. It’s a bit more verbose, but it’s reliable and doesn’t require external libraries.
I’ve encountered similar issues with date formatting in Zapier’s NodeJS environment. It can be frustrating when code that works elsewhere doesn’t behave as expected on their platform.
One workaround I’ve found effective is using the moment-timezone library. Zapier includes it by default, so you don’t need to install anything extra. Here’s how you could modify your code:
const moment = require('moment-timezone');
const input = '2023-05-15T10:30:00Z';
const formatted = moment(input).tz('America/New_York').format('MM/DD/YYYY, h:mm:ss A');
console.log(formatted);
This approach has consistently worked for me in Zapier’s environment. It handles the timezone conversion correctly and gives you flexibility in formatting.
If you prefer not to use external libraries, another option is to manually adjust the UTC time to Eastern Time. However, be cautious with this method, especially around daylight saving time changes.