On 11 February 2004 20:26, Richard Day wrote:

> Hello:
> 
> 
> Environment:
>     Linux server
>     PHP 4.3.4
> 
> This code:
> 
>     echo '<br>'.strftime('%T %Z',mktime()).', Timestamp='.mktime();
>     echo '<br>'.strftime('%T GMT',gmmktime()).',
> Timestamp='.gmmktime();
> 
> yields this result:
> 
>     23:52:08 EST, Timestamp=1076475128
>     18:52:08 GMT, Timestamp=1076457128
> 
> Why? GMT should be 5 hours ahead of EST, not 5 behind. Right?
> What am I
> missing here??

Well, that looks very suspicious, and probably not for the reasons you're
thinking.

I can explain why you get that result, but it means that either (a) there's
a bug in gmmktime(), or (b) the documentation for gmmktime() is wrong (or,
at least, misleading).  So, let's take it step-by-step:

1. gmmktime(), according to the manual, should use the "current
corresponding GMT value" for it's omitted arguments.
2. In my book, at 23:52:08 EST that means it should be using 04:52:08 GMT on
the following day (we'll discuss this later, since, whilst giving a
different result, it still wouldn't produce what you're expecting!).
3. However, let's guess that gmmktime() is actually using the *local* time
value of 23:52:08, but treating it as if it were GMT.
4. In which case, you'll get a timestamp for 23:52:08 GMT.
5. Because timestamps are absolute (not adjusted for timezone), this is also
the timestamp for 18:52:08 EST.
6. 18:52:08 is what you're getting printed.
7. QED.

This behaviour is *not* what the manual says should happen, and in my
opinion is counter-intuitive.  However, if gmmktime() were to behave as the
manual, at least how I read it, suggests, this is what would happen:

1. gmmktime() would calculate a timestamp for 04:52:08 GMT (next day).
2. Because timestamps are absolute, this is also the timestamp for 23:52:08
EST.
3. So strftime() still outputs 23:52:08.

Ergo, this is not the way to produce an adjusted time.  One way to do what
you're looking for is to feed the same timestamp to date('%H:%i:%s') and
gmdate('%H:%i:%s).  If you want something you can feed to strftime() for the
GMT date, you need to acquire your timezone's offset from GMT in seconds
(e.g. with date('Z');) and subtract that from the timestamp.

HTH

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to