嗨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
但没有产生这样的格式。现在需要帮助伙伴,谢谢...
答案 0 :(得分:1)
echo date("P", strtotime("$tz2"));
回波
GMT-0600
我不担心该地区的名称。
答案 1 :(得分: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)美合资/纽约