Reputation: 35
I have a date format like this 'Tue May 01 00:00:00 +1000 2012' (from array data on json file)
when I use date() function it returning April, :D
echo date('F Y', strtotime('Tue May 01 00:00:00 +1000 2012'));
//it returning "April 2012"
Any ideas how to fix this?
Many Thanks!
Upvotes: 0
Views: 907
Reputation: 437774
Instead of using the old date/time functions that mess things up because they implicitly involve your local time zone, use DateTime
:
$date = new DateTime('Tue May 01 00:00:00 +1000 2012');
echo $date->format('F Y');
This will also work corrrectly for any date, regardless of the timezone (UTC+10 hours or anything else).
Upvotes: 2
Reputation: 80657
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
Upvotes: 2