1

嗨,伙计们,

我有一个时区字符串,例如:

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

尝试参考:日期

但不会产生这种格式。现在需要帮助的朋友,谢谢...

4

2 回答 2

1

新编辑 - 试试这个...

$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

于 2012-11-05T13:08:23.283 回答
1

echo date("P", strtotime("$tz2"));

回声

GMT-0600

恐怕该地区的名称不可用。

于 2012-11-05T13:06:59.440 回答