In a React/Next.js App, is there a way to always make sure, anywhere in the world it shows the local time in CEST. Let’s say; I get the GMT time from my backend, which I want to offset, to display the CEST timezone offset of that time. That same time should be displayed anywhere in the world. Case: Exhibition Opening in Berlin at 6pm local time, shouldn't be displayed as different time in another timezone! Important in my case is also, that it has to work as well if the server and client are in different timezones as the function may be called on either side. This was my attempt:
const initialDate = new Date("Fri, 07 May 2021 17:00:00 GMT");
const userTimezoneOffset = initialDate.getTimezoneOffset() * 60000;
const date = new Date(initialDate.getTime() - userTimezoneOffset);
I am struggling to fix this one for a while now, and I failed to find a solution working for me. When the app is deployed, it is 4pm instead of 6pm. It works correctly in dev mode as well as when building locally, it even works when I change my local time with .env.TZ. But the timezone is always off when deploying to vercel. I assume it has something to do, wether the time is rendered server-side or client-side…