Time zone detection by city/country name php 8.1 / Symfony 5.4

118 views Asked by At

What are the ways to get the time zone given the city code in php8.1 with Symfony 5.4?

1

There are 1 answers

1
Chafik Kerboute On

you can try using Intl componenet check the documentation here IntlComponenet

use Symfony\Component\Intl\Timezones;

\Locale::setDefault('en');

 $timezones = Timezones::getNames();

 $timezone = Timezones::getName('Africa/Nairobi');
 // => 'East Africa Time (Nairobi)'

Note: I took this code from documentation