The Laravel Timezones package is a convenient solution for Laravel developers who need to include a dropdown menu of timezones in their applications. This package simplifies the process of incorporating a timezone selection feature, saving developers valuable time and effort.
You can install the package via composer:
composer require baspa/laravel-timezonesuse Baspa\Timezones\Facades\Timezones;
//
$groupedTimezones = Timezones::toArray(grouped: true);use Baspa\Timezones\Facades\Timezones;
//
$timezones = Timezones::toArray();use Baspa\Timezones\Facades\Timezones;
//
$timezones = Timezones::excludeContinents(['Africa', 'America'])
->toArray();$timezones = Timezones::showOffset()->toArray();
// or
$timezones = Timezones::showOffset(showOffset: false)->toArray();To include general timezones like GMT or UTC use the includeGeneral method.
$timezones = Timezones::includeGeneral()->toArray();To include country names alongside timezone labels use the showCountry method. This uses PHP's built-in timezone data combined with the league/iso3166 package to provide accurate country names.
// Basic usage with country names
$timezones = Timezones::showCountry()->toArray();
// Output: "Amsterdam (Netherlands)"
// Combined with other methods
$timezones = Timezones::showCountry()
->showOffset(false)
->toArray();
// Output: "Amsterdam (Netherlands)"
// With full continent names preserved
$timezones = Timezones::showCountry()->toArrayWithContinents();
// Output: "Europe / Amsterdam (Netherlands)"
// Grouped by continent with country names
$timezones = Timezones::showCountry()->toArray(grouped: true);composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.
