【问题标题】:strtotime time zone offset with UTC?strtotime 与 UTC 的时区偏移?
【发布时间】:2011-12-25 17:17:24
【问题描述】:

$bet_closing 在 WordPress 管理员中设置为:格林威治标准时间 2011 年 11 月 9 日上午 6:59

太平洋标准时间 11 月 9 日凌晨 12:01(加利福尼亚时间)。但我希望能够在管理员中添加另一个选项,以便他们可以选择基于 UTC 的时区。在我自己的州,它是 UTC -7。我试过这个“2011 年 11 月 9 日上午 6:59 格林威治标准时间 -0700”,但没有成功。

// Auto Close Bet
$now = time();
$bet_closing = strtotime(get_option('cp_gamble1_endtime'));
if ($bet_closing > $now) { // Betting Open!
    $output .= 'On';
    $cp_gamble1_onoff = true;
    update_option('cp_gamble1_onoff', $cp_gamble1_onoff);
} else {
    $cp_gamble1_onoff = false;
    update_option('cp_gamble1_onoff', $cp_gamble1_onoff);
    $output .= 'Over';
}

我确信有更好的方法来做到这一点。如果有的话我会全神贯注:)

【问题讨论】:

  • 你试过没有GMT的字符串吗?

标签: php wordpress timezone


【解决方案1】:

刚刚测试了这个(我输入了命令,下一行给出了结果):

var_dump(strtotime("November 9, 2011 6:59AM GMT"));

int(1320821940)

同:

var_dump(strtotime("November 9, 2011 6:59AM GMT -0700"));

int(1320821940)

但没有GMT 效果很好:

var_dump(strtotime("November 9, 2011 6:59AM -0700"));

int(1320847140)

【讨论】:

    【解决方案2】:

    您可以在调用strtotime()函数之前使用date_default_timezone_set()函数设置时区

    【讨论】:

    • time 总是以 UTC 表示,因为它总是自纪元以来的秒数,所以它总是相同的。您想转换 strtotime 之前或之后的时区,具体取决于您使用结果的方式。
    猜你喜欢
    • 1970-01-01
    • 2018-02-12
    • 2016-08-24
    • 1970-01-01
    • 2014-02-04
    • 2011-11-08
    • 2018-03-01
    • 2017-10-18
    • 1970-01-01
    相关资源
    最近更新 更多