CKTIS / PHP
DateTimeZone
Nazwana strefa stosuje regionalne reguły do danej chwili. getOffset podaje liczbę sekund na wschód od UTC ze znakiem, zależną np. od pory roku.
Wersja: PHP 8.4; repository runtime, production runtime not attested
Składnia
new DateTimeZone("Europe/Warsaw")Nazwana strefa stosuje regionalne reguły do danej chwili. getOffset podaje liczbę sekund na wschód od UTC ze znakiem, zależną np. od pory roku. Stałe przesunięcie nie ma historii zmian sezonowych. setTimezone zmienia zapis chwili, zachowując timestamp.
$zone=new DateTimeZone("Europe/Warsaw");
$winter=new DateTimeImmutable("2024-01-15T12:00:00Z"); $summer=new DateTimeImmutable("2024-07-15T12:00:00Z");
echo json_encode([$zone->getOffset($winter),$zone->getOffset($summer),$summer->getTimestamp()===$summer->setTimezone($zone)->getTimestamp()]);
[3600,7200,true]
Przykłady
<?php
$zone=new DateTimeZone("Europe/Warsaw");
$winter=new DateTimeImmutable("2024-01-15T12:00:00Z"); $summer=new DateTimeImmutable("2024-07-15T12:00:00Z");
echo json_encode([$zone->getOffset($winter),$zone->getOffset($summer),$summer->getTimestamp()===$summer->setTimezone($zone)->getTimestamp()]);
Wynik
[3600,7200,true]