【问题标题】:Change UTC time to IST (Asia/Kolkata) time in PHP在 PHP 中将 UTC 时间更改为 IST(亚洲/加尔各答)时间
【发布时间】:2017-05-22 20:03:47
【问题描述】:
while($chat = $result->fetch_object()){

        // Returning the GMT (UTC) time of the chat creation:

        $chat->time = array(
            'hours'     => date('H',strtotime($chat->ts)),
            'minutes'   => date('i',strtotime($chat->ts))
        );

我正在使用此代码在聊天消息旁边显示时间。如何更改此代码以在 IST 时区显示输出时间?谢谢

【问题讨论】:

    标签: php


    【解决方案1】:

    您有几种方法可以实现这一点,一种简单的方法是在date 之前使用date_default_timezone_set,即:

    date_default_timezone_set('Asia/Kolkata');
    

    【讨论】:

      【解决方案2】:

      我不建议您存储该值并在数据库中使用特定时区。相反,我强烈建议您使用转换只是为了显示给your users the right time where they are, Stack already discussed about that。我知道您已经解决了您的问题,如果有人提出您的问题并决定使用 date_default_timezone_set 或在 INI 中设置,我只想为此付出两分钱。

      无论如何,UTC seems to be a very stable candidate with good timezone translation support.

      【讨论】:

        猜你喜欢
        • 2016-03-17
        • 1970-01-01
        • 2020-08-03
        • 1970-01-01
        • 2020-10-28
        • 1970-01-01
        • 2021-10-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多