
Wikis & learning
Find the local date for an event
An instant has a different calendar date depending on the timezone used to display it. Keep the instant and the display zone separate.
An instant has a different calendar date depending on the timezone used to display it. Keep the instant and the display zone separate.
How it works
DateTimeImmutable returns a new value when a timezone changes; the original value stays available for comparison.
PHP example
<?php
$event = new DateTimeImmutable('2025-01-01T00:30:00+00:00');
$local = $event->setTimezone(new DateTimeZone('America/Los_Angeles'));
echo $local->format('Y-m-d');Expected result
2024-12-31
Try a variation
Display the same instant in Asia/Tokyo. Compare both calendar dates.
Discussion
Sign in to participate.



