What is the correct way to define a timezone per customer?

Hello guys!

I have a platform that will be used by customers from different timezones.

What is the best way for me to handle this situation?

The first step should be to store the timezone in the customer’s table.

What are the next steps?

Can someone help me please?

Thanks!

1 Like

You have to save timezone information per each user then set it up for each request

Let say your user Identity class inherits from User class which have timezone attribute

then you can add to your web.config

[
    'components' => [
        //....
    ],
    'on beforeRequest' => function ($e) {
        date_default_timezone_set(Yii::$app->user->identity->timezone);
    },
]

It worked!
Thank you brother!

1 Like