【发布时间】:2015-12-07 18:51:01
【问题描述】:
我要解析 Twitter API created_at 值(存储到变量中),如下所示:
2011 年 8 月 28 日星期日 19:31:16 +0000
进入这个:
8 月 28 日 19:31
但我需要它能够识别时区。关于如何使用php 进行此操作的任何想法?
使用John Flatness 建议的第二个选项后,我收到此错误:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Sao_Paulo' for 'BRT/-3.0/no DST' instead' in /misc.php:4
Stack trace:
#0 /misc.php(4): DateTime->__construct('Sun Aug 28 19:3...')
#1 /tabs/home.php(29): format_date(Object(SimpleXMLElement), 'America/Sao_Pau...')
#2 {main}
thrown in /misc.php on line 4
【问题讨论】:
-
您可以将时区作为第二个参数传递给
DateTime构造函数以防止出现该错误(或在 php.ini 中设置 date.timezone 设置或使用date_default_timezone_set显式设置默认时区)。