add one day to DateTime based on timestamp

From: Date: Thu, 14 Jun 2012 17:44:55 +0000
Subject: add one day to DateTime based on timestamp
Groups: php.general 
Request: Send a blank email to php-general+get-318238@lists.php.net to get a copy of this message
Hello, When I create a DateTime object from a UNIX timestamp, and then add a one day interval, PHP adds 25 hours instead of 24. Is this a bug, or something to do with the time zones? Here are the commands I'm running from my shell: ---------- $ date Wed Jun 13 06:08:24 PDT 2012 $ php -r '$d=new DateTime("@1082444400"); print $d->format("r")."\n"; $d->add(new DateInterval("P1D")); print $d->format("r")."\n";' Tue, 20 Apr 2004 07:00:00 +0000 Wed, 21 Apr 2004 08:00:00 +0000 ---------- If I set the time zone on the new DataTime object to America/Los_Angeles before adding the 1 day period, then it works as expected. ---------- $ php -r '$d=new DateTime("@1082444400"); $d->setTimeZone(new DateTimeZone("America/Los_Angeles")); print $d->format("r")."\n"; $d->add(new DateInterval("P1D")); print $d->format("r")."\n";' Tue, 20 Apr 2004 00:00:00 -0700 Wed, 21 Apr 2004 00:00:00 -0700 ---------- Regards, Shailesh

« previous php.general (#318238) next »