Joomla 2.5显示错误的日期时间 [英] Joomla 2.5 displays wrong datetime

查看:103
本文介绍了Joomla 2.5显示错误的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在自己制作的自定义组件中创建了以下代码:

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

$date = date('m/d/Y h:i:s a', time())."<br>";
echo  'Current date and time is: ' . $date;

$date = JFactory::getDate();
echo 'Current date and time is: ' . $date->toFormat() ."<br>";

第一个代码正确显示了日期时间,但是第二个代码显示了+3小时的时间

The first code displays the datetime correctly, but the second one displays the time +3 hours

我已经检查了configuration.php文件和公共$ offset ='Europe/Athens';并且是正确的.我也在系统配置菜单中更改设置,但似乎没有任何方法可以修复JFactory :: getDate()以显示正确的时间. 我想念什么?

I have checked the configuration.php file and the public $offset = 'Europe/Athens'; and is correct. I am also changing the settings from the system configuration menu but nothing seems to be fixing the JFactory::getDate() to display the correct time. What am I missing?

推荐答案

对于JFactory::getdate()中的第二个参数-我认为您应该在第二个参数中指定时区,例如JFactory::getDate($time=now, $tzOffset)

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();

顺便说一句,在组件中使用JHtml :: date()可能会更容易,因为它涉及的行数更少,并且更多是"Joomla本机".请参见此处上的API页面.然后使用如下代码:

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);

其中$input =现在指定使用时间现在".第二个参数是日期的格式,第三个参数表示时间设置已设置服务器时间.而不是用户选择的时间.

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.

这篇关于Joomla 2.5显示错误的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆