hi Mates,
我有一个时区字符串喜欢:
Mon Nov 05 2012 06:54:06 GMT-0600 (Central America Standard Time)
需要将这些字符串转换为标准时区格式使用 php
(GMT-06:00)-Central America
代码:
echo $tz = "Mon Nov 05 2012 06:54:06 GMT-0600 (Central America Standard Time)";
echo $tz2 = substr($tz, 0, 34);
echo date("P", strtotime("$tz2"));
结果:
Mon Nov 05 2012 06:52:37 GMT-0600 (Central Standard Time)
Mon Nov 05 2012 06:52:37 GMT-0600
+00:00
尝试参考: date
但不会产生这种格式。现在需要帮助伴侣,谢谢...
新编辑 - 尝试此...
$tz = "Mon Nov 05 2012 06:54:06 GMT-0600 (Central America Standard Time)";
$time = explode(" ",$tz);
$timezone = explode("(", str_replace(")","",$tz)); // would be better to use a regex
$new_time = "(".$time[5].")-".$timezone[1];
echo $new_time; // gives (GMT-0600)-Central America Standard Time
退出前的旧代码.....
$tz = "Mon Nov 05 2012 06:54:06 GMT-0600 (Central America Standard Time)";
$new_time = strtotime($tz);
$new_date = date( '(P)-e', $new_time );
echo $new_date;
( - 05:00)-America/new_york
echo date("P", strtotime("$tz2"));
回声
GMT-0600
我恐怕该地区的名称。