根据用户时区设置设置CodeIgniter时间戳



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

例如:

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

我解决了我的问题。我抛弃了CI日期助手,然后选择了默认的PHP。这比进行反复试验要好得多,并且始终获得偏离实际时间的偏移。

@astound的答案也对此有所帮助。

最新更新