Even though I set the workfow timezone when I run new Date() inside in the node function, it brings the date with the default timezone.
I would like to use new Date() inside a node function.
How can I adjust the time zone in this case?
Even though I set the workfow timezone when I run new Date() inside in the node function, it brings the date with the default timezone.
I would like to use new Date() inside a node function.
How can I adjust the time zone in this case?
Hey @Edson_Rodrigues,
The system you’re running n8n on might have a different timezone. You can setup the environment variable TZ to configure the timezone. This should solve your issue.
Hi Harshil, i have an issue as well about time, my server locale time is GMT +7 , I already set 2 environment variable for n8n GENERIC_TIMEZONE and TZ to be Asia/Bangkok, but when I see node execution date, is always keep UTC 0 time.
do you have any idea? this only applied to n8n only, the other apps respect the vps local time.
Thank you for your time
same issue
Still the same. Set timezone to Australia/Sydney but it says it is still UTC
With a different standard time zone configured in the environment variables, I’ve found that Luxon uses the custom timezone for an individual workflow (configured in workflow settings), if you do it like this:
const luxonDate = DateTime.fromJSDate(new Date());
Speaking of the code node, that is.
Confusingly enough, at the same time, all the other Luxon DateTime methods (e.g. .now()) and n8n’s custom variables ($now, $today) stoically prefer the instance’s timezone in the code node whereas in the expressions of the Edit Fields (Set) node, the very same Luxon and custom variables take the workflow’s custom timezone as you would expect it.
You gotta know the quirks, I guess…
Thanks that worked correctly and is returning the correct time.
// Get today's date
const luxonDate = DateTime.fromJSDate(new Date());
// Format the date to "YYYY-MM-DD"
const formattedDate = luxonDate.toFormat('yyyy-MM-dd');
// Return the formatted date
return {
json: {
formattedDate
}
};