gpt4 book ai didi

php - Joomla 中的日期转换为用户时区

转载 作者:行者123 更新时间:2023-12-02 17:38:12 24 4
gpt4 key购买 nike

感谢您的阅读。

只需要知道如何将从 gmtime 中的 sql 表获取的日期时间转换为用户时区中的日期时间。

以下是我的代码,但似乎不起作用..

//WHERE $post_arr[5] is date from sql

$user_date=convert_date_for_user($post_arr[5]);

function convert_date_for_user($date_time){
$user = JFactory::getUser();
$db = JFactory::getDBO();

$timezone=$user->getParam('timezone');

echo $tz_offset;
$user_date = JFactory::getDate($date_time,$timezone);
$user_date_str = $user_date->toUnix(true);

return $user_date_str;
}

它可以转换,但我从上面的代码中得到的时间都是错误的。

最佳答案

最简单的方法:

$useUserTimeZone = true;
JHtml::date($sqlGmtTimestamp , 'D F n, Y', $useUserTimeZone);

$sqlGmtTimestamp 采用 GMT 时间戳/日期时间

$useUserTimeZone 是使用用户时区的标志,否则将使用服务器时区。

更多详细信息请参见:http://docs.joomla.org/API16:JHtml/date

关于php - Joomla 中的日期转换为用户时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17158920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com