Display timezone related to user location (Laravel)

Viewed 143

I use laravel 6, and it's 'timezone' => 'UTC'. we have thousands users from across the world. ex. Japan, US, China, India, Turkish and ..., In this case we should display post timezone related to the country timezone.

2 Answers

In order to use users timezone, first that timezone needs to be stored somewhere

for example in DB table users under column timezone

and then if you need the current time in users timezone you just call this method:

$usersCurrentTime = now($user->timezone)->format('Y-m-d H:i:s');

That will give you the current time in users timezone.

 $date= \Carbon\Carbon::setLocale('en');
Related