FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » strtotime
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: strtotime [message #175211 is a reply to message #175209] Wed, 24 August 2011 07:31 Go to previous message
alvaro.NOSPAMTHANX is currently offline  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
--
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: different servers, different results with a file upload
Next Topic: "><script>alert('ss')</script>
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 03:04:34 GMT 2024

Total time taken to generate the page: 0.04779 seconds