PHPs DateTime is not doing what I expect it to do here....
class Time_model extends CI_model
{
public $time_zone;
public $tz;
public $dt;
public function __construct()
{
date_default_timezone_set('UTC');
$this->time_zone = 'Pacific/Auckland';
$this->tz = new DateTimeZone($this->time_zone);
$this->dt = new DateTime('now', $this->tz);
}
/**
* dates
*/
public function getDate()
{
$this->dt->getTimezone(); // <--- shows that the timezone is auckland where it is the 02/10/2016
return $this->dt->format('Y-m-d'); // <--- yet returns the 01/10/2016!
}
}
In Auckland it is a Sunday, yet even when I explicitly change the TimeZone nothing changes, it still shows up as Saturday.
How do I get DateTime to change the date to match the timezone??
Furthermore, if passing the new DateTimeZone object into the DateTime object does absolutely nothing, then what is the point of passing it in the first place? This is really bugging me because I know I have got something completely wrong!