0

我有这样的日期格式“Tue May 01 00:00:00 +1000 2012”(来自 json 文件上的数组数据)

当我使用 date() 函数时,它返回 April,:D

      echo date('F Y', strtotime('Tue May 01 00:00:00 +1000 2012'));

      //it returning "April 2012"

任何想法如何解决这一问题?

非常感谢!

4

2 回答 2

2

You will need to check both the timezones. Or set a custom one for both date and strtotime calls.


Since you are using +1000 as your timezone-offset; I'm assuming it is Australia. You can use the date_default_timezone_set() call to set timezone to Australia.

echo date('F Y', strtotime('Tue May 01 00:00:00 +1000 2012'));
date_default_timezone_set('Australia/Queensland');
echo date('F Y', strtotime('Tue May 01 00:00:00 +1000 2012'));

Here is the codepad link: http://codepad.org/tPC8DEQp

于 2013-04-26T23:23:03.580 回答
2

不要使用旧的日期/时间函数,因为它们隐含地涉及您的本地时区,所以使用DateTime

$date = new DateTime('Tue May 01 00:00:00 +1000 2012');
echo $date->format('F Y');

无论时区如何(UTC+10 小时或其他任何时间),这也适用于任何日期。

于 2013-04-26T23:53:12.517 回答