php
datetime
ai_generated
true
Fatal error: Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone (US/Pacific-New) in /var/www/app/src/Utils/DateHelper.php:18
ID: php/timezone-invalid
92%Fix Rate
94%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 83 | active | — | — | — |
Root Cause
Invalid timezone errors occur when PHP encounters an unrecognized timezone identifier. This can happen due to deprecated timezone names (e.g., US/Pacific-New), missing timezone database, user input with invalid timezones, or mismatched ICU/IANA timezone data.
genericWorkarounds
-
95% success Use IANA timezone identifiers and validate user input against timezone_identifiers_list()
Always use canonical IANA names like 'America/New_York', 'Europe/London', 'Asia/Tokyo'. Validate user-provided timezones: if (!in_array($tz, timezone_identifiers_list())) { throw new InvalidArgumentException('Invalid timezone'); } -
90% success Set a default timezone in php.ini and application configuration
In php.ini: date.timezone = UTC. In application bootstrap: date_default_timezone_set('UTC'). Store all datetimes in UTC in the database and convert to the user's timezone only for display.
Dead Ends
Common approaches that don't work:
-
Using timezone abbreviations (EST, PST, CST) instead of IANA identifiers
75% fail
Timezone abbreviations are ambiguous. CST can mean Central Standard Time (US), China Standard Time, or Cuba Standard Time. PHP may resolve them incorrectly, causing silent data corruption in date calculations.
-
Hardcoding UTC offset like +05:30 instead of using named timezones
60% fail
Fixed UTC offsets do not account for daylight saving time transitions. Using +05:30 instead of Asia/Kolkata works for India, but using -05:00 instead of America/New_York will be wrong for half the year.
Error Chain
Leads to:
Preceded by:
Frequently confused with: