note 118797 modified in datetime.settimezone by cmb

From: Date: Thu, 18 Feb 2016 11:39:20 +0000
Subject: note 118797 modified in datetime.settimezone by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-204982@lists.php.net to get a copy of this message
It appears that what forzi at mail333 dot com said is correct. When you reset the timezone on a DateTime object using a timezone that was instantiated with a GMT offset (e.g. <?php new DateTimeZone('-0500'); ?>) the timestamp as reported by <?php $dt->format('U'); ?> changes. However, the value reported by <?php $dt->getTimestamp(); ?> does _not_ change. Interestingly, once <?php $dt->getTimestamp(); is called, the value from <?php $dt->format('U'); ?> starts returning the correct timestamp. This appears to be a bug. In any case, other output values from format() seem to be accurate, and the true timestamp is always accessible via getTimestamp(). --was-- This is a revised note with additional information: It appears that what forzi at mail333 dot com said is correct. When you reset the timezone on a DateTime object using a timezone that was instantiated with a GMT offset (e.g. <?php new DateTimeZone('-0500'); ?>) the timestamp as reported by <?php $dt->format('U'); ?> changes. However, the value reported by <?php $dt->getTimestamp(); ?> does _not_ change. Interestingly, once <?php $dt->getTimestamp(); is called, the value from <?php $dt->format('U'); ?> starts returning the correct timestamp. This appears to be a bug. In any case, other output values from format() seem to be accurate, and the true timestamp is always accessible via getTimestamp(). http://php.net/manual/en/datetime.settimezone.php

« previous php.notes (#204982) next »