【问题标题】:Joomla 3.1: how to get timezone offset?Joomla 3.1:如何获得时区偏移?
【发布时间】:2013-09-26 20:51:27
【问题描述】:

有人知道如何在 Joomla 3.1 中获取系统时区偏移量吗?我尝试了以下方法:

    return JFactory::getConfig()->getValue('offset');

但这会导致以下错误:

    Fatal error: Call to undefined method JRegistry::getValue()

感谢您为我指明正确方向的任何信息......

【问题讨论】:

    标签: joomla timezone-offset


    【解决方案1】:

    试试这个:

    $config = JFactory::getConfig();
    $offset = $config->get('offset');
    

    【讨论】:

    • 我已经尝试过您的建议,但这会返回(例如)“Africa/Abidjan”......但是我正在寻找数值。有什么想法吗?
    • 你可以使用 DateTimeZone::getOffset() 方法来得到这个:php.net/manual/en/datetimezone.getoffset.php
    【解决方案2】:

    试试:

    $timezone = new DateTimeZone(JFactory::getConfig()->get('offset'));
    $offset   = $timezone->getOffset(new DateTime)/3600;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-03
      • 2018-08-31
      • 1970-01-01
      • 2021-08-28
      • 2013-10-17
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多