CKTIS / PHP
Dates et fuseaux horaires
DateTimeImmutable renvoie un nouvel objet après modification.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
$next = $date->modify("+1 day");DateTimeImmutable renvoie un nouvel objet après modification. Les opérations calendaires suivent le fuseau et un jour de changement d’heure peut durer 23 ou 25 heures. Soustrayez les timestamps Unix pour la durée et choisissez un fuseau nommé pour l’heure civile.
$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]
Exemples
<?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]);
Résultat
["12:00 +01:00","12:00 +02:00",23]