note 43211 added to function.time

From: Date: Mon, 14 Jun 2004 11:55:52 +0000
Subject: note 43211 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-71038@lists.php.net to get a copy of this message
in response to the comments by gnif at spacevs dot com and by HW: time() does NOT add the timezone-offset! However, the date()-function does so before outputting the formated time. This also means that, at least in theory, time() will return the exact SAME timestamp on the server as it does on the client side, regardless of the time zone they are in. But naturally, there is no way in PHP to run time() on the client side. More precisely: As stated in the documentation, time() returns the number of seconds since the epoch. This is defined to be in UTC (or GMT) by the POSIX standard, and at least on my boxes it is exactly that (PHP 4.3.4 on Apache 2.0.48 on RedHat, and PHP 4.3.3 on Apache 1.3.29 on Debian). The fact that date() adds the timezone-offset before formating is compliant to the way this is done by many API's, for instance by the Perl time libraries. However, it does not seem to be at all possible to have date() display the date in a different timezone, without manually adding/subtracting the offset from the epoch-value -- wich is not the Right Thing to do, beacuse it is not reflected by the T and Z format patterns. IMHO, date() should have an optional parameter for the time zone, which could then be used by Z and T. A simple offset in seconds would be sufficient, but a symbolic zone name, or at least a symbolic offset of the form +0500, would be very handy. As of now, to display a formated time/date in GMT, use the method suggested by gnif at spacevs dot com: <? print date("H:i:s",time()-date("Z")) . " GMT"; ?> this will work fine als long as you don't have T or Z in you date-format-pattern -- that would lead to confusion. Also, the naming of the gmtime() function he suggested is misleading and should be avoided. HTH ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43211 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43211&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43211&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71038) next »