When using the PHP DateTime
class and try to set a DateTimeZone
I get different results depending on how I set it: using the DateTime::__cons
This is normal behaviour.
When you don't specify the timezone in the constructor, the default timezone is used, i.e what was set using date_default_timezone_set().
When you then call:
$dateTimeTwo->setTimezone(new DateTimeZone('America/Los_Angeles'));
It moves the date set in the default timezone into the new timezone.
1) (constructor) set date in 'America/Los_Angeles'
2) (setter) set date in default timezone, move date to 'America/Los_Angeles'
Your default timezone was probably UTC or something close. You told the computer to set 2014-08-01 at UTC. You then asked to switch to the 'America/Los_Angeles' timezone which is 7 hours earlier thus by changing the date to 2014-07-31 at 17:00.