有没有一种方法可以从时间戳整数值中找到时区字符串?
My Integer value : +5.5
我想得到什么
Asia/Colombo
我正在使用WordPress,是否有一种简单的方法可以在WP上获得它?
我会用 DateTimeZone::listIdentifiers()
$time_zones = DateTimeZone::listIdentifiers();
foreach ($time_zones as $time_zone) {
$date = new DateTime('now', new DateTimeZone($time_zone));
$offset_in_hours = $date->getOffset() / 60 / 60;
echo "{$time_zone}: ($offset_in_hours)";
}
这将输出类似:
Asia/Choibalsan: (9)
Asia/Colombo: (5.5)
Asia/Damascus: (3)
Asia/Dhaka: (6)
Asia/Dili: (9)
Asia/Dubai: (4)
然后,您可以将此代码包装在插件/简码中,并使用输出反向搜索您的时区。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句