Harsh Gandhi
Harsh Gandhi

Reputation: 59

I have error In timezone setting

I m using following code.

static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'UTC');

'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)->setTimezone(static::$timezone),

but I m getting error.

Fatal error: Call to a member function setTimezone() on a non-object

So what is wrong in the code

Upvotes: 1

Views: 311

Answers (1)

Kevin
Kevin

Reputation: 41893

No need to use ->setTimeZone there. Just make sure static::$timezone is indeed a DateTimeZone object since you already fed it with that:

static::$timezone = new DateTimeZone('America/Los_Angeles');

Then on creating the DateTime object:

'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)

Upvotes: 1

Related Questions