I’m having trouble with timezone conversion in my Zapier Code step using NodeJS. Here’s what I’m attempting to do:
// Sample data for testing
var messageData = {
text: 'Timestamp: 2018-03-06T13:58:35.660Z\nUser: Admin\nMessage: hello\n\nTimestamp: 2018-03-06T14:00:16.093Z\nUser: Admin\nMessage: world'
};
// Main conversion logic
var result = messageData.text.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/gm, function(match){
var originalDate = new Date(Date.parse(match));
var convertedDate = originalDate.toLocaleString('en-US', {
timeZone: "America/New_York",
hour12: true
});
return convertedDate;
});
console.log(result);
The problem is that the timezone conversion doesn’t seem to work properly. When I run this code in Zapier, it processes without errors but the dates don’t get converted to Eastern time like they should. The same toLocaleString method works fine in other environments. Has anyone experienced similar issues with timezone conversion in Zapier Code steps?
yeah, i had the same issue with zapier’s node.js too. instead of toLocaleString, i just did the offset calculation manually. subtract 5 hours for standard time and 4 for daylight saving. this way it actually works in their sandbox.
Zapier’s Code step runs in a sandbox that doesn’t have the timezone data toLocaleString needs. Hit this same issue about six months ago building a similar workflow. What worked for me was ditching JavaScript’s timezone handling completely - just use UTC offset calculations instead. For Eastern time, you need UTC-5 for standard time and UTC-4 for daylight saving. Check the date range to figure out which one applies, or hardcode the offset if your use case is narrow enough. The Date object’s getUTCHours(), getUTCMinutes(), etc. work fine in Zapier’s environment, so build your conversion logic around those.
I’ve hit this exact same issue with Zapier’s NodeJS environment. Your code logic is fine - the problem is Zapier’s stripped-down Node environment. It doesn’t include the full ICU timezone database that toLocaleString needs. Here’s what worked for me: ditch toLocaleString and do manual timezone conversion instead. Use getUTCHours() and apply the Eastern offset (-5 or -4 for DST). You could try moment-timezone if Zapier allows it, but manual offset calculation is way more reliable there. Your regex and date parsing look solid - that’s not the issue.