note 23569 deleted from function.mktime by sniper
| From: | sniper@php.net | Date: | Tue, 04 Nov 2003 13:11:30 +0000 |
| Subject: | note 23569 deleted from function.mktime by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59881@lists.php.net to get a copy of this message | ||
Note Submitter: jason@narnarnar.com
----
I found unexpected results with the combination of time(), mktime(), and date(). I'm using a
script that gets the last time a user loaded a page and it uses $last_click=time() to store the time
since the epoch into a tabble. Ok, so I wanted to make a format of DD.MM.YYYY @ HH:MM:SS so I
figured I'd just use:
$last_online=date("M.d.Y @ h:i:s", mktime(0, 0, $last_click, 1, 1, 1970);
figuring that it would determine the date by the seconds since epoch. Oddly, this always gave me a
return that was 20 hours shy. I changed it to:
$last_online=date("M.d.Y @ h:i:s",mktime(20, 0, $last_click, 1, 1, 1970)
and it did work, but I didn't like the fact that I had to add the extra 20 hours. Then, I
realized that mktime() returns seconds as well, so all I had to do was use:
date("M.d.Y @ h:i:s", $last_click);
I'm not sure why this gave me that response, so if anyone can give me a answer, it would be
apreciated. But I just thought I'd share this info in case someone else fell into the same
pitfall.