CKTIS / PHP
Dates and time zones
DateTimeImmutable returns a new object when modified.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$next = $date->modify("+1 day");DateTimeImmutable returns a new object when modified. Calendar operations follow the selected time zone. Around a daylight-saving transition, adding one calendar day can span 23 or 25 elapsed hours. Use Unix timestamp differences for elapsed seconds and specify a named zone for civil-time rules.
$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]
Examples
<?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]);
Result
["12:00 +01:00","12:00 +02:00",23]