nehero / friendlytimezone
使用地理位置名称友好地显示时区给您的用户
v3.0.2
2022-04-05 21:56 UTC
Requires
- php: ^8.0
- illuminate/collections: ^9.6
Requires (Dev)
- pestphp/pest: ^1.20
This package is auto-updated.
Last update: 2024-09-11 14:53:36 UTC
README
数据来源于 Microsoft Time Zone Index Values。
一些地区受到 此 Stack Overflow 答案 的影响。
⚠️ 此软件包已重写为版本 3,以支持更多灵活的时区处理方式,并集成了现代 PHP 功能
安装
自 v3.0 起,此软件包需要 PHP 8.0+
您可以通过 composer 安装此软件包
composer require nehero/friendlytimezone
使用方法
// Illuminate\Support\Collection of Nehero\Timezone $timezones = Nehero\FriendlyTimezone\FriendlyTimezone::timezones(); // properties available to you foreach ($timezones as $timezone) { echo $timezone->friendlyName; // Saskatchewan (string) echo $timezone->timezone; // America/Regina (string) echo $timezone->offset; // -6 (int|float) echo $timezone->getFormattedOffset(); // -6:00 (string) } // common formatting for dropdowns $timezones->map(fn ($tz) => [ 'label' => "(UTC{$tz->getFormattedOffset()}) {$tz->friendlyName}"), // (UTC+6:00) Saskatchewan 'value' => $tz->timezone, // America/Regina ]); // need it in descending order? // can manipulate it however you want with // common collection or native array/iterable functions $timezones->sortByDesc(fn ($tz) => $tz->offset)->map(...);
支持时区
是否有缺失?欢迎提交 pull 请求和问题!
点击查看当前所有支持时区的表格
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
贡献
如果您对任何映射的地区有更好的建议,请提交 pull 请求,并包括更改的准确来源。
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。