Mailinglisten-Archive |
Ahoi,
it's simple: UTC und CEST haben 2h Zeitversatz. Damit wird aus der einen Variante 2.11.2013 1:00 morgens und aus der anderen der 1.11.2013 23:00:
<?php
ini_set("date.timezone", "Europe/Berlin");
$add=7*86400;
$t1=strtotime("2013-10-26 00:00:00 UTC");
$t2=strtotime("2013-10-26");
$t1a=$t1+$add;
$t2a=$t2+$add;
$t1d=date("Y-m-d H:i:s", $t1a);
$t2d=date("Y-m-d H:i:s", $t2a);
print "$t1 - $t1a - $t1d";
print "\n-------\n";
print "$t2 - $t2a - $t2d";
?>
Ergebnis:
1382745600 - 1383350400 - 2013-11-02 01:00:00
-------
1382738400 - 1383343200 - 2013-11-01 23:00:00
Viele Grüße,
Volker
Am 22.10.2013 um 14:29 schrieb Michael Fuhrmann <technik at piaunddirk.de>:
> Servus,
>
>
>
> ich habe gerade folgendes herausgefunden. Wenn ich auf
> strtotime(‚2013-10-26‘) 7 * 86400 draufaddiere, dann erhalte ich den
> 2013-11-01 statt 2013-11-02.
>
> Mein Fix ist strtotime(‚2013-10-26 00:00:00 UTC‘). Da erhalte ich
> komischerweise den 2013-11-02.
>
>
>
> Wieso ist das so?
>
>
>
> Code:
>
>
>
> public static function adddays($date, $days = 1)
>
> {
>
> if ($days == 0) return $date;
>
> return date('Y-m-d', strtotime($date) + 86400 * $days);
>
> }
>
>
>
> return date('Y-m-d', strtotime($date . ' 00:00:00 UTC') + 86400 * $days);
>
>
>
> Liegt es vielleicht an einer Fehlinterpretation von date() oder strtotime(),
> dass eine von beiden die voreingestellte Zeitzone ignoriert?
>
>
>
>
>
> Beste Grüße/Cordialement:
>
> Michael Fuhrmann
>
> --
> ** Allgemeine deutschsprachige PHP-Liste: php at lists.phpbar.de **
> Informationen: http://www.phpbar.de
> http://lists.phpbar.de/cgi-bin/mailman/listinfo/php
php::bar PHP Wiki - Listenarchive