【问题标题】:Ignore BST with php strtotime() function使用 php strtotime() 函数忽略 BST
【发布时间】:2014-01-28 19:18:36
【问题描述】:

有没有办法让我告诉 strtotime() 函数不要将我给它的时间更改为 BST?即如果做

date('g.ia', strtotime("2014-06-25T19:30"))

我想得到晚上 7:30,就像我进入了一样

date('g.ia', strtotime("2014-06-25T19:30"))

(第一个当前返回下午 6:30)

我知道我可以手动检查日/月并在必要时添加一个小时,或者自己从字符串中解析时间,但这两种解决方案听起来都有些混乱(我必须这样做这在很多地方)。

对不起,如果我遗漏了一些明显的东西,对 php 来说很新

【问题讨论】:

    标签: php date strtotime


    【解决方案1】:

    函数date() 将根据您的时区设置格式化时间。也就是说,您的示例没有意义,因为 strtotime() 将使用当前时区设置将输入转换为 unix 时间戳,然后函数 date() 将再次使用该时区设置来格式化时间戳。您必须在 strtotime()date() 函数调用之间更改时区设置,例如 this demo

    您可以简单地使用 DateTime 扩展,其中隐含地告诉您的时间是在哪个时区:

    $dt = new DateTime('2014-06-25T19:30', new DateTimezone('Europe/London'));
    echo $dt->format('g.ia');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 2011-10-08
      相关资源
      最近更新 更多