|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-04-28 21:06 UTC] gamin at centras dot lt
Description:
------------
Simple script... doesn't matter how much time i run it - strototime("now") produces same result for whole day. On next month day it produces same result. Seems i didn't have any problem on RC1.
Reproduce code:
---------------
$str = "now";
$timestamp = strtotime($str);
echo "$str == " . date('l dS of F Y h:i:s A', $timestamp) . "<br />\n";
$timestamp = time();
echo "Good is " . date('l dS of F Y h:i:s A', $timestamp) . "<br />\n";
Expected result:
----------------
now == Wednesday 28th of April 2004 10:02:54 PM
Good is Wednesday 28th of April 2004 10:02:54 PM
Actual result:
--------------
now == Wednesday 28th of April 2004 12:00:00 AM
Good is Wednesday 28th of April 2004 10:02:54 PM
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
Im seeing the same thing on FreeBSD 5 with PHP5 rc2. code: <?php $strtime = strtotime('now'); printf(' Now: %11s %s Str time: %11s %s ' , time() , date('d M Y @ H:i:s ') , $strtime , date('d M Y @ H:i:s ', $strtime) ); ?> Expected: Now: 1084875653 18 May 2004 @ 11:20:53 Str time: 1084875653 18 May 2004 @ 11:20:53 Actual: Now: 1084875653 18 May 2004 @ 11:20:53 Str time: 1084834800 18 May 2004 @ 00:00:00Hi derick, Yes that is strange, What about adding an optional parameter to the function to set toggle between real now and gnu now? Something like: int strtotime ( string time [, int now] [, bool gnu = false])The functionality is maintained in RC3. I needs the realtime for logging of process. My workaround is to do this: $str=date('d F Y h:i:s A'); $timestamp = strtotime("$str");I've been using strtotime() to calculate relative shifts in time, ie. $real_now = strtotime("2004-07-15 00:16:35"); $exactly_one_day_ago = strtotime("-1 day", $real_now); echo date('Y-m-d H:i:s', $exactly_one_day_ago) Expecting "2004-07-14 00:16:35" but getting: "2004-07-14 00:00:00" I'm sure there's a way around this, but I'm really not that bright... so I had to jump back to php4 for the time being. So I also think that the "now" parameter should be real now, not GNU "now".Until this behaviour is fixed so that now() means 'real now' and not 'GNU now' here is a workaround that works in both PHP 4 and PHP 5: $real_now = date('Y-m-d H:i:s'); $dt1 = strtotime("$real_now -1 day"); $dt2 = date('Y-m-d H:i:s', $dt1);