Emmanuelpcg's avatar

How to get client timezone dynamically ?

I'm making an API that will be available globally, and I need the timezone of the request made by the client, to generate an token if it is between the allowed times.

Is there any way to validate which timezone a request came from just using the server side?

0 likes
1 reply
martinbean's avatar
Level 80

@emmanuelpcg Not in a server request. A timezone will only be sent if you send it from the client:

axios.post('/api/example', {
    timezone: getTimezone(),
});

A request coming to your server will just have the time of the request. You can then use that time in your local timezone or UTC. A HTTP request has no concept of timezones.

1 like

Please or to participate in this conversation.