CKTIS / PHP
Date e fusi orari
DateTimeImmutable restituisce un nuovo oggetto alla modifica.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
$next = $date->modify("+1 day");DateTimeImmutable restituisce un nuovo oggetto alla modifica. Le operazioni di calendario seguono il fuso e un giorno al cambio dell’ora può durare 23 o 25 ore. Sottrarre timestamp Unix per i secondi trascorsi e usare un fuso con nome per l’ora 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]
Esempi
<?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]);
Risultato
["12:00 +01:00","12:00 +02:00",23]