Zapier NodeJS代码中toLocaleString()时区转换失效问题求助
toLocaleString() Timezone Conversion in Zapier Node.js Hey there! Let's dig into why your EST timezone conversion isn't working in Zapier's Node.js step—this is a super common gotcha with server-side runtimes like Zapier's, and it usually ties back to how the environment handles timezone data.
Common Causes & Fixes
1. You're Using a Timezone Abbreviation Instead of a Standard ID
EST is a shorthand timezone abbreviation, but many server-side environments (including Zapier's) don’t reliably support these abbreviations. Instead, use the IANA standard timezone ID America/New_York—this automatically covers both EST (winter) and EDT (summer) without extra work, making it far more reliable.
Try updating your code to this:
const currentDate = new Date(); // Use the official IANA timezone ID for Eastern Time const formattedESTDate = currentDate.toLocaleString('en-US', { timeZone: 'America/New_York', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); // Critical: Output the result for Zapier to pass along output = [{ formattedESTDate }];
2. Zapier's Runtime May Lack Full ICU Data
The toLocaleString() function depends on ICU (International Components for Unicode) data to process timezones. Sometimes, server-side environments ship with a minimal ICU build that doesn’t include all timezone datasets.
To test if this is the issue, add a quick check to your code:
// Verify if America/New_York is supported in the environment const supportedTimezones = Intl.supportedValuesOf('timeZone'); console.log('America/New_York is supported:', supportedTimezones.includes('America/New_York'));
If the log returns false, you’ll need a workaround to calculate the timezone offset manually.
3. Manual Timezone Offset Workaround (For Missing ICU Data)
If the standard method fails, you can calculate the Eastern Time offset while accounting for daylight saving time. Here’s a reliable way to do it:
const currentDate = new Date(); const utcTimestamp = currentDate.getTime(); // Check if daylight saving time (EDT) is active for Eastern Time const isEDT = currentDate.toLocaleString('en-US', { timeZone: 'America/New_York', timeZoneName: 'short' }).includes('EDT'); // EDT = UTC-4, EST = UTC-5 (convert offset to milliseconds) const offsetMinutes = isEDT ? -4 * 60 : -5 * 60; const estTimestamp = utcTimestamp + (offsetMinutes * 60 * 1000); const formattedESTDate = new Date(estTimestamp).toLocaleString('en-US'); output = [{ formattedESTDate }];
Final Tips
- Stick to IANA timezone IDs (like
America/New_York) instead of abbreviations—they’re universally supported and handle daylight saving time automatically. - Don’t forget to explicitly output your result with
output = [...]—Zapier won’t pick up the converted value otherwise, even if the logic works.
内容的提问来源于stack exchange,提问作者Sean Keough

