Joomla 2.5 displays wrong datetime

前端 未结 1 1931
我在风中等你
我在风中等你 2021-01-03 09:27

I have Created this code in a custom component that I made:

$date = date(\'m/d/Y h:i:s a\', time()).\"
\"; echo \'Current date and time is: \' . $d
相关标签:
1条回答
  • 2021-01-03 09:42

    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.

    0 讨论(0)
提交回复
热议问题