Date() formatting discrepancy between preview and output

Hey there,
First, thanks to the team for a sleek, powerful tool! I’ve set myself up with a telegram-github-obsidian quick note taking app, but there’s one detail I can’t figure out…

When I put the following in the Github Node Commit message expression field it outputs the right date in preview, BUT on Github it always returns the UTC one (whether in the file contents or in the commit message):


{{Date().toLocaleString('en-US', {timeZone: "Asia/Hong_Kong"})}}

Preview Ouput (both in the expression result field and the actual field on main edit screen)

Tue Mar 29 2022 11:39:21 GMT+0800 (Hong Kong Standard Time)


Tue Mar 29 2022 03:40:53 GMT+0000 (Coordinated Universal Time)

Ideas as to what I’m overlooking here?

n8n 0.166.0 (docker behind https reverse proxy) on ubuntu 21.10

Hi @ludoct, welcome to the community :tada:

Does this work when using an expression like {{new Date().toLocaleString('en-US', {timeZone: "Asia/Hong_Kong"})}}?

My JS understanding is that Date() on it’s own is a shorthand for new Date().toString(), but you probably want new Date().toLocaleString() here.

1 Like

Hi MutedJam,

Thanks, that works!

Github export:

Old date: Wed Mar 30 2022 13:55:21 GMT+0000 (Coordinated Universal Time)
New date: 3/30/2022, 9:55:21 PM

There still is the funny behavior in the preview - but I guess that’s on n8n’s team’s table, the above showing:

Old date: Wed Mar 30 2022 21:56:04 GMT+0800 (Hong Kong Standard Time)
New date: 3/30/2022, 9:56:04 PM


So the preview is rendered by your browser rather than n8n. Your expression would just run pure JavaScript, so your browser behaviour might differ from what Node.js is doing (the server component n8n uses to actually execute the workflow).

In order to have a more predictable behaviour you can try using the Date&Time node to force a specific format like so:

You can then reference the field returned by the Date & Time node in your GitHub node.