1

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

1
  • ->setTimezone is not needed, just make sure static::$timezone is indeed a DateTimezone object Commented Sep 20, 2014 at 5:32

1 Answer 1

1

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.