【问题标题】:Setting Codeigniter Timestamp in accordance to user Timezone settings根据用户时区设置设置 Codeigniter 时间戳
【发布时间】:2017-05-30 06:36:34
【问题描述】:

如何根据用户的时区设置记录时间戳?

例如:

  1. 用户的时区设置为 $my_tz = "UP3";
  2. 用户将项目的截止日期设置为 $time_to_set = "2017-05-31 03:15 PM";
  3. 例如,我需要具有不同时区设置的用户根据他们的时区正确转换时间(例如,用户 1:UP3,用户 2:UP8)。他们需要正确地看时间。我尝试设置,但偏移量似乎有 +1 小时的差异,而且不准确。
  4. 我需要将时间设置为时区 (UP3) 以转换为 (UTC) 基准,而不会超出 +1 小时。

非常感谢!

这是我的代码,您可以测试一下以了解我的意思。

    $my_tz = "UP3";
    $utc_time = local_to_gmt(time());
    $current_time = gmt_to_local($utc_time, $my_tz, FALSE);

    echo "Current Time: ".unix_to_human($current_time)."</br>";
    echo $current_time;
    echo "</br></br></br></br>";

    $time_to_set = "2017-05-31 03:15 PM";
    $time_set_unix = human_to_unix($time_to_set);
    $time_to_normal = local_to_gmt($time_set_unix, "UP8", FALSE);

    echo $time_to_set."</br>";
    echo $time_set_unix."</br>";
    echo $time_to_normal."</br>";
    echo unix_to_human($time_to_normal)."</br>";

【问题讨论】:

标签: php codeigniter time unix-timestamp timestamp-with-timezone


【解决方案1】:

我解决了我的问题。我放弃了 CI 日期助手并选择了默认的 PHP 助手。这比反复试验并总是得到一个偏离实际时间的偏移量要好得多。

@astound 的回答对此也有帮助。

【讨论】:

  • 谢谢你,请在评论中投赞成票,感谢我的回答,谢谢
猜你喜欢
  • 1970-01-01
  • 2023-03-23
  • 2017-06-23
  • 2013-06-29
  • 2011-07-27
  • 2013-05-29
  • 2011-01-17
  • 2020-06-06
  • 1970-01-01
相关资源
最近更新 更多