Eduardo Rosa
Eduardo Rosa

Reputation: 139

Joomla! Timezone

I'm a little confused with something: if I setup the timezone on Joomla! Admin (Global Configuration > Location Settings > Server Time Zone) the line below would show the date in my timezone, right?

$JDate = JFactory::getDate('now');
echo $JDate->format('Y-m-d H:i:s', true);

Why I need to do this:

$JDate = JFactory::getDate('now', new DateTimeZone('America/Sao_Paulo'));
echo $JDate->format('Y-m-d H:i:s', true);

I understand it wrong?

Upvotes: 2

Views: 1502

Answers (1)

David Fritsch
David Fritsch

Reputation: 3741

JFactory::getDate() will always stay in UTC. This is good for storing dates into the database and other calculations.

For displaying a date to a user, it is recommended to use JHtml::date(). This will automatically use your timezone setting.

JHtml::date('now', 'Y-m-d H:i:s');

For more information and to see the code behind this function: http://docs.joomla.org/API16:JHtml/date

Upvotes: 4

Related Questions