note 51328 added to function.date
| From: | .) | Date: | Sun, 27 Mar 2005 19:53:26 +0000 |
| Subject: | note 51328 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87063@lists.php.net to get a copy of this message | ||
PHP date, strftime and mktime functions are DST sensitive
This means if the server is setup to be US GMT-5 and DST sensitive then the mentioned functions add,
extract or do nothing with the current DST.
Without a given timestamp:
- date() uses the current server time.
This is DST affected if the server uses DST settings
- gmdate() uses the current GMT time, it extracts server GMT & DST.
With a given timestamp:
- date() is affected if the server uses DST settings
* if current time is DST but the given time isn't then DST is extracted
* if current time isn't DST but the given time is then DST is added
- gmdate() is affected, it extracts server GMT & DST on the given timestamp
So for example $timestamp is a GMT based time.
You modify the $timestamp for a "member" his personal timezone and dst.
The member has setup GMT-5 and DST sensitive
You add his GMT-5 to the $timestamp and check if the $timestamp is in DST or not
Then all the above functions are screwed in normal use.
<?php
$timestamp = 1122814800; // 07/31/05 13:00:00 GMT
$user_gmt = -5;
$user_dst = 1;
$timestamp += ($user_gmt*3600); // to user time
$timestamp += 3600; // user time is in DST
echo date("H:i:s",$timestamp);
echo gmdate("H:i:s",$timestamp);
?>
If server is GMT+0 in summer (DST is on) the above outputs
08:00:00
07:00:00
If server is GMT+0 in winter (DST is off) the above outputs
09:00:00
08:00:00
If server is GMT-5 in winter (DST is off) the above outputs
09:00:00
03:00:00
So if you work with local times and the server isn't GMT based be carefull how you output the
times to your members.
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51328
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51328&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51328&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51328&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51328&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51328&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51328&report=yes
Search -- http://master.php.net/manage/user-notes.php