To handle a php datetime timezone correctly, create DateTimeImmutable objects with an explicit DateTimeZone, store and compare moments in UTC, and convert with setTimezone() only when you display a value. PHP never guesses where your user lives, so every date either carries a zone or falls back to the server default.
This guide builds on basic date formatting and shows how the DateTime family treats zones, how to convert between them, and how to avoid daylight saving surprises.
A DateTimeZone object names a zone using an identifier from the IANA time zone database, such as UTC, Europe/London, America/New_York or Asia/Kolkata. Every DateTime and DateTimeImmutable object has one zone attached, and that zone decides how the stored instant is shown as a wall-clock time.
The format characters T (abbreviation) and P (offset from UTC) show which zone is attached. Use e to print the identifier.
Functions such as date() and the constructor without an explicit zone use the default zone. It comes from the date.timezone setting in php.ini, and you can override it at runtime.
A good rule for servers and applications is to set the default to UTC, keep all stored data in UTC, and treat user-specific zones as a display concern. Changing the default in the middle of a request is a source of subtle bugs, so do it once during bootstrap, or pass the zone explicitly everywhere.
setTimezone() does not change the instant. It changes how that instant is expressed. On a DateTimeImmutable it returns a new object.
Notice that Sydney lands on the next calendar day. Never assume two cities share a date.
You can pass three kinds of zone value, and they behave differently.
| Kind | Example | Follows daylight saving? | Recommended? |
|---|---|---|---|
| Identifier | Europe/Paris | Yes, using historic and future rules | Yes |
| Offset | +05:30 | No, fixed offset | Only for a known fixed offset |
| Abbreviation | EST | No, one fixed meaning | Avoid, it is ambiguous |
An identifier is the only form that knows the rules of that region, including past changes. An abbreviation such as CST can mean US Central, China or Cuba, so do not store it.
To list valid identifiers, use DateTimeZone::listIdentifiers():
Validate a zone sent by a user by catching the exception the constructor throws.
When clocks move forward, one local hour does not exist. When they move back, one local hour happens twice. Working in UTC avoids both problems, but display code may still hit them.
In the United States, clocks moved forward on 8 March 2026. Adding one day keeps the wall-clock time at noon. Adding 24 hours adds exactly 86,400 seconds and lands at 13:00 local time. Pick the one that matches your intent: "same time tomorrow" for a reminder, 24 elapsed hours for a timeout.
Follow this procedure for any application with users in more than one region.
UTC at startup.setTimezone().No. It changes only the zone attached to the same instant, so the displayed hour changes while the moment stays the same. Comparing two objects with < or == compares the instants, not the printed text.
Use UTC. It has no daylight saving, which makes logs, databases and comparisons predictable. Convert for display only.
Offsets change with daylight saving, and not every region changes on the same day. Always use identifiers rather than fixed offsets for people.
PHP ships with its own copy of the time zone database, which is updated with PHP releases and can be refreshed by updating the timezonedb data on your system. Keep PHP patched when a country changes its rules.
Attach a DateTimeZone to every date, keep stored values in UTC, and convert with setTimezone() for display. Use IANA identifiers instead of abbreviations, validate user zones by catching the exception, and choose between add(P1D) and add(PT24H) depending on whether you mean calendar or elapsed time.