1

I've been looking for a while, it used to work but it does'nt anymore and I can't find why. Does one of you have an idea?

$utc_time = DateTime::createFromFormat('Y-m-d H:i:s', $time, new DateTimeZone('US/Eastern'));
$utc_time->setTimeZone(new DateTimeZone("UTC")); // This line returns the error.
return $utc_time->format($dateformat);

I get this error: Fatal error: Call to a member function setTimeZone() on a non-object.

Thanks a lot for your help, I hope it's something dumb and that I was just lost...

4
  • which PHP version are you using ? > 5.2.0 ? Commented May 10, 2013 at 3:02
  • Don't forget that $time needs to be a string representing the time. Commented May 10, 2013 at 3:08
  • Your code works just fine with PHP 5.3 See Codepad That means that the only problem is with $time variable Commented May 10, 2013 at 3:09
  • Don't use the US/Eastern alias. Use America/New_York instead. See here Commented May 10, 2013 at 15:03

1 Answer 1

1

In DateTime::createFromFormat, it returns FALSE on failure, which leads to your error.

What is the value of $time ?

Sign up to request clarification or add additional context in comments.

1 Comment

I was using $time in a wront format. I just make sure I use the good one now. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.