| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2008-06-04 10:27 UTC] derick@php.net
  [2008-06-04 11:47 UTC] peter dot bex at solide-ict dot nl
  [2008-06-04 11:54 UTC] derick@php.net
  [2008-06-04 12:01 UTC] peter dot bex at solide-ict dot nl
  [2008-06-04 12:07 UTC] derick@php.net
  [2008-06-04 12:24 UTC] peter dot bex at solide-ict dot nl
  [2008-07-20 21:01 UTC] derick@php.net
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 09:00:01 2025 UTC | 
Description: ------------ When creating a datetime object from a string that includes timezone offset information (like "10:00:00+02:00"), the timezone object's name can not be used for creating new timezone objects or setting the default timezone. In effect, it's an "impossible object": there's no way to recreate an object like that yourself. This also means you would get unexpected results when using, for example, strftime(). If you use date_default_timezone_set to change the timezone to the object's timezone and print the date info, it will give you the wrong output. Reproduce code: --------------- <?php date_default_timezone_set('UTC'); echo "Before: ".date_default_timezone_get()."\n"; $foo = new datetime('10:00:00+02:00'); $name = $foo->getTimeZone()->getName(); echo "Setting timezone: $name\n"; date_default_timezone_set($name); echo "After: ".date_default_timezone_get()."\n"; echo "strftime: ".strftime('%H:%M:%S', $foo->format('U'))."\n"; $bar = new datetimezone($name); echo "datetimezone object name: ".$bar->getName(); ?> Expected result: ---------------- Before: UTC Setting timezone: GMT+02 After: GMT+02 strftime: 10:00:00 datetimezone object name: GMT+02 (not sure if GMT+02 is the correct timezone name. In any case, it should be some timezone name that's accepted by other timezone-related functions/classes) Actual result: -------------- Before: UTC Setting timezone: +02:00 After: UTC strftime: 08:00:00 PHP Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (+02:00)' in /path/to/index.php:10