Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2954
| From | "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: strtotime |
| Date | 2011-08-24 09:31 +0200 |
| Organization | http://alvaro.es/ |
| Message-ID | <j329cf$g8l$1@dont-email.me> (permalink) |
| References | <0f753a9b-9229-4dd7-ab20-0e750ed9baed@m6g2000prh.googlegroups.com> |
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
--
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
strtotime BKDotCom <kent.brad@gmail.com> - 2011-08-23 19:09 -0700 Re: strtotime dougatmilmacdotcom@example.com (Doug Miller) - 2011-08-24 03:09 +0000 Re: strtotime "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-08-24 09:31 +0200
csiph-web