首页 > 解决方案 > php如何设置时区,如(utc + 1 utc-5)而不是(欧洲/阿姆斯特丹......)

问题描述

我想显示世界上所有国家/地区的日期和时间问题是 40 多个国家/地区使用 utc+1 并且很难为每个国家/地区指定特定时区示例:伦敦、摩洛哥和尼日尔具有相同的日期和时间

london =>  date_default_timezone_set('Europe/London');
 morocco =>  date_default_timezone_set('Africa/Casablanca');
 niger =>  date_default_timezone_set('Africa/Lagos');

我的第一个问题是为什么 php 不支持:

date_default_timezone_set('utc+1')
date_default_timezone_set('utc+2')

以及如何为所有国家/地区定义一个时区,使用 utc+5 或 utc+2

标签: php

解决方案


你看过时区列表吗?格林尼治标准时间的会做你想做的

https://www.php.net/manual/en/timezones.others.php

Etc/GMT+1   Etc/GMT+10  Etc/GMT+11  Etc/GMT+12
Etc/GMT+2   Etc/GMT+3   Etc/GMT+4   Etc/GMT+5
Etc/GMT+6   Etc/GMT+7   Etc/GMT+8   Etc/GMT+9
Etc/GMT-0   Etc/GMT-1   Etc/GMT-10  Etc/GMT-11
Etc/GMT-12  Etc/GMT-13  Etc/GMT-14  Etc/GMT-2
Etc/GMT-3   Etc/GMT-4   Etc/GMT-5   Etc/GMT-6
Etc/GMT-7   Etc/GMT-8   Etc/GMT-9   Etc/GMT0

推荐阅读