7

I am migrating a component from joomla 2.5 to joomla 3.2, I got an error in the method where am using setOffset

//old version used in joomla 2.5 

$data->setOffset(JFactory::getConfig()->get('offset'));

I referred the Link : http://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_3_and_Joomla_Platform_12.2

//after i  refered the above link i changed my code  like 

if($date === null ) {   
  $date = JFactory::getDate();
  $tz = JFactory::getConfig()->get( 'offset' );

  // new Version 
  $date->setTimezone($tz);

  $date = $date->format( "%Y-%m-%d" );
}

but i am getting an error -

DateTime::getTimezone() expects exactly 0 parameters, 1 given  /example.php on line 5 .

Plz need your solution to fix the error

1
  • In your code is no getTimezone() so where is line 5 in example.php? btw, you can use $date = JFactory::getDate('now', $tz); Commented Apr 26, 2014 at 8:45

1 Answer 1

6

Finally I found the solution for this Error by passing the object of DateTimeZone as a parameter (notice the $date->setTimezone(new DateTimeZone($tz)); in the code bellow). It's working fine.

if($date === null )
{
  $date = JFactory::getDate();
  $tz = JFactory::getConfig()->get( 'offset' );

  $date->setTimezone(new DateTimeZone($tz)); //here!

  $date = $date->format( "Y-m-d" );
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.