strtotime [message #175209] |
Wed, 24 August 2011 02:09 |
BKDotCom
Messages: 7 Registered: October 2010
Karma: 0
|
Junior Member |
|
|
Can anyone explain this to me:
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?
|
|
|
Re: strtotime [message #175210 is a reply to message #175209] |
Wed, 24 August 2011 03:09 |
dougatmilmacdotcom
Messages: 24 Registered: May 2011
Karma: 0
|
Junior Member |
|
|
In article <0f753a9b-9229-4dd7-ab20-0e750ed9baed(at)m6g2000prh(dot)googlegroups(dot)com>, BKDotCom <kent(dot)brad(at)gmail(dot)com> wrote:
> Can anyone explain this to me:
>
> 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?
http://php.net/manual/en/function.strtotime.php
"The function expects to be given a string containing an English date format
and will try to parse that format into a Unix timestamp (the number of seconds
since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or
the current time if now is not supplied."
Note in particular the the last nine words: "or the current time if now is not
supplied."
Your first call to strtotime() supplies the 'now' parameter. The second one
does not. That they do not produce the same result should not be a surprise.
|
|
|
Re: strtotime [message #175211 is a reply to message #175209] |
Wed, 24 August 2011 07:31 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma: 0
|
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
--
|
|
|