Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

DateTimeZone

Use a named time zone to apply regional offset rules to an instant. getOffset returns signed seconds east of UTC and can differ by season in the same zone.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

new DateTimeZone("Europe/Warsaw")

Use a named time zone to apply regional offset rules to an instant. getOffset returns signed seconds east of UTC and can differ by season in the same zone. A fixed offset has no daylight-saving transition history. setTimezone changes the presentation of an instant, not its 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]

Examples

<?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()]);

Result

[3600,7200,true]

Sources