CKTIS / PHP
Zeit und Zeitzonen
DateTimeImmutable liefert nach Änderungen ein neues Objekt.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$next = $date->modify("+1 day");DateTimeImmutable liefert nach Änderungen ein neues Objekt. Kalenderoperationen folgen der Zeitzone, ein Tag am Zeitwechsel kann 23 oder 25 Stunden dauern. Für verstrichene Sekunden Zeitstempel subtrahieren, für Ortszeitregeln eine benannte Zone verwenden.
$d=new DateTimeImmutable("2024-03-30 12:00:00",new DateTimeZone("Europe/Warsaw"));$next=$d->modify("+1 day");echo json_encode([$d->format("H:i P"),$next->format("H:i P"),($next->getTimestamp()-$d->getTimestamp())/3600]);
["12:00 +01:00","12:00 +02:00",23]
Beispiele
<?php
$d=new DateTimeImmutable("2024-03-30 12:00:00",new DateTimeZone("Europe/Warsaw"));$next=$d->modify("+1 day");echo json_encode([$d->format("H:i P"),$next->format("H:i P"),($next->getTimestamp()-$d->getTimestamp())/3600]);
Ergebnis
["12:00 +01:00","12:00 +02:00",23]