Joomla 2.5 displays wrong datetime

佐手、 提交于 2019-11-30 16:04:40

For your second parameter in the JFactory::getdate() - I think you should be specifying the time zone in a second parameter so something like JFactory::getDate($time=now, $tzOffset)

$date = JFactory::getDate($input='now', 'UTC');
// Set the correct time zone based on the server configuration.
$config = JFactory::getConfig();
$date->setOffset($config->getValue('config.offset'));
//Print out Date
echo $date->toFormat();

On a side note it may be easier to use JHtml::date() in the component as this involves less lines and is more 'Joomla native'. See the API page on this here. Then use a code like :

echo JHtml::date($input = 'now', 'm/d/Y h:i:s a', false);

Where $input = now specifies to use the time 'now'. The second parameter is your format for the date and the third parameter means the time setting is set the server time. Rather than the users selected time.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!