|
Posted by Derek Fountain on 04/06/07 16:25
I'm using PHP4 and have got myself confused over timezones.
I've put a datetime into my MySQL table as a GMT time. MySQL shows me
the data as '2007-04-06 16:04:56'. I put that in there just after 5pm,
and as I'm in London (GMT+0), but we're now on British Summer Time
(GMT+1), that appears to be correct.
I want to get that datetime out again, and print it into my webpage,
keeping it as GMT. i.e. I want PHP to treat that time as '2007-04-06
16:04:56'. If I say:
$date = date( 'r', $timestamp );
then it says:
Fri, 06 Apr 2007 16:04:56 +0100
The time is right, but it's reporting my local timezone. If I say:
$date = gmdate( 'r', $timestamp );
then it says:
Fri, 06 Apr 2007 15:04:56 +0000
Now it's got the timezone as I want it (+0000, which is GMT) but the
time is wrong.
It seems that PHP's gmdate() treats the input timestamp value as being
local time, and therefore corrects it by either marking it with the
local timezone (as per the date() function), or 'correcting' it to GMT
(as per the gmdate() function).
Either way, given that I'm starting with an absolute, GMT based time
stamp, this isn't helpful!
I *think* I've got the right timestamp in my MySQL table, and *think*
I'm interpreting the datetime incorrectly in PHP. Can someone explain
where I'm going wrong and how I get PHP to just convert my GMT date/time
number to a GMT date/time string?
--
Derek Fountain on the web at http://www.derekfountain.org/
Navigation:
[Reply to this message]
|