Change Time Zone env in Vercel
Unanswered
Carolina Dog posted this in #help-forum
Carolina DogOP
In vercel docs, I can't add a TZ (timezone) in my enviroment variable.
https://vercel.com/docs/concepts/projects/environment-variables/reserved-environment-variables
Is there a way to set up a time zone for nodejs without doing this??
Thank you.
https://vercel.com/docs/concepts/projects/environment-variables/reserved-environment-variables
Is there a way to set up a time zone for nodejs without doing this??
Thank you.
12 Replies
@Carolina Dog In vercel docs, I can't add a TZ (timezone) in my enviroment variable.
https://vercel.com/docs/concepts/projects/environment-variables/reserved-environment-variables
Is there a way to set up a time zone for nodejs without doing this??
Thank you.
when you host on vercel, it is impossible.
You can't change the time zone on where your application is built on Vercel. – Lee Robinsonhttps://stackoverflow.com/questions/67252528/what-time-zone-does-vercel-use-during-ssr-in-next-js#comment118945388_67252528
if you use hacky ways like
process.env.TZ = ... then it might be possible but i wouldn't rely on it@joulev if you use hacky ways like `process.env.TZ = ...` then it *might* be possible but i wouldn't rely on it
Carolina DogOP
But where would you put it though?
I'm trying to create a date object where the date is today but at 12 pm at a certain local time (UTC + 7).
I tried using new Date().setHours(12, 0, 0, 0) this won't work because in RSC component is rednered on server, means UTC time (12 pm UTC).
I tried using new Date().setUTCHours(5, 0, 0, 0) (this is 12 pm in UTC+7) but this only works at 7am ~ 12am UTC+7. (It doesn't work in 12AM until 7am UTC+7)
I tried using new Date().setHours(12, 0, 0, 0) this won't work because in RSC component is rednered on server, means UTC time (12 pm UTC).
I tried using new Date().setUTCHours(5, 0, 0, 0) (this is 12 pm in UTC+7) but this only works at 7am ~ 12am UTC+7. (It doesn't work in 12AM until 7am UTC+7)
you should just use UTC everywhere and render the time with your timezone in the frontend
@joulev you should just use UTC everywhere and render the time with your timezone in the frontend
Carolina DogOP
But in my app the schedule is only for 12 pm UTC + 7, By using what you said, the displayed time will change depending on the timezone of the user?
@joulev you can hardcode UTC+7 to the rendering logic
Carolina DogOP
Yes true, I actually tried this and works perfectly for toLocaleString or toLocaleDateString. I used the above trick also for other components.
But my problem is actually the opposite, I'm trying to get the Date object from the information "today" and "12 PM UTC +7", not converting it to string.
But my problem is actually the opposite, I'm trying to get the Date object from the information "today" and "12 PM UTC +7", not converting it to string.
@Carolina Dog Yes true, I actually tried this and works perfectly for toLocaleString or toLocaleDateString. I used the above trick also for other components.
But my problem is actually the opposite, I'm trying to get the Date object from the information "today" and "12 PM UTC +7", not converting it to string.
how are you trying to get the date object from that information? whatever library you use it should have an option to use custom timezone
@joulev how are you trying to get the date object from that information? whatever library you use it should have an option to use custom timezone
Carolina DogOP
Not really, setHours() method doesn't have custom timezone method. Only toLocaleString or toLocateDateString has one?
I don’t see how you can use setHours to go from “today†to a Date object…
As in, how do you get the date object from that information string?