in Open Source

JFactory::getDate() doesn’t automatically add offset

By default, calling JFactory::getDate() doesn’t automatically apply the timezone offset.   The default date/time is GMT.

By using the following code, you can set the offset from the global joomla configuration file

<?php
$thisJApp = &JFactory::getApplication();
$thisJDate = JFactory::getDate();
$thisJDate ->setOffset($thisJApp ->getCfg(‘offset’));
echo $thisJDate->toFormat(“%A %d %b %Y”);
?>

If you want to set the date from a logged in user you can try:

<%

$JUser =& JFactory::getUser();
$JDate = JFactory::getDate();
echo $JDate->toFormat().'<br>';
echo ‘offset=’ . $JDate->getOffset() . ‘<br>';
$JDate->setOffset($JUser->getParam(‘timezone’));

%>