Re: strtotime [message #175211 is a reply to message #175209] |
Wed, 24 August 2011 07:31 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma:
|
Senior Member |
|
|
El 24/08/2011 4:09, BKDotCom escribió/wrote:
> shouldn't these to both return the same timestamp?
>
> $ts = 1204351200;
> strtotime('+1 month',$ts); // returns 1207026000
> strtotime('@'.$ts.' +1 month')); // returns 1207029600... where's the
> extra 1 hour coming from?
Hmmm...
date_default_timezone_set('UTC');
echo date('r e', strtotime("@1204351200")) . PHP_EOL;
echo date('r e', strtotime('+1 month', 1204351200)) . PHP_EOL;
echo date('r e', strtotime("@1204351200 +1 month")) . PHP_EOL;
date_default_timezone_set('Europe/Madrid');
echo date('r e', strtotime("@1204351200")) . PHP_EOL;
echo date('r e', strtotime('+1 month', 1204351200)) . PHP_EOL;
echo date('r e', strtotime("@1204351200 +1 month")) . PHP_EOL;
Sat, 01 Mar 2008 06:00:00 +0000 UTC
Tue, 01 Apr 2008 06:00:00 +0000 UTC
Tue, 01 Apr 2008 06:00:00 +0000 UTC
Sat, 01 Mar 2008 07:00:00 +0100 Europe/Madrid
Tue, 01 Apr 2008 07:00:00 +0200 Europe/Madrid
Tue, 01 Apr 2008 08:00:00 +0200 Europe/Madrid
This is really tricky.
My guess is that in the first form you are asking PHP to add one month
to a given date and PHP considers the local time zone when doing date
maths. However, in the second form PHP thinks you are defining a date as
"1204351200 seconds and one month since Unix Epoch" and PHP disregards
the time zone because Unix timestamps are universal.
That's probably the key point: "manipulate a date" vs "define a timestamp".
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|