【问题标题】:strtotime() function returning incorrect datestrtotime() 函数返回不正确的日期
【发布时间】:2017-03-16 06:35:17
【问题描述】:

即使我将时区设置为UTC-9,我也会得到下周的日期。

当UTC更改日期即16-03-2017 00:00:00,而UTC-9时区仍为15-03-2017 15:00:00时,strtotime()函数返回下周的日期。

$last_time_instance = strtotime(''Wednesday' ' 16:00:00);

变量$last_time_instance 正确返回时间,但将日期转发到下一周,即22-03-17

我该如何解决这个问题?

【问题讨论】:

  • 在程序中使用 date_default_timezone_set()。
  • 我应该在 strtotime() 函数中使用吗?
  • 在您的程序顶部,或就在strtotime()之前

标签: php date datetime utc strtotime


【解决方案1】:

您可以将时区UTC-9 附加到字符串:

$last_time_instance=strtotime('Wednesday 16:00:00 UTC-9');  // 1490803200

$time_instance_formatted=date('d-m-Y H:i:s',$last_time_instance);  // 29-03-2017 12:00:00

【讨论】:

  • 抱歉!我刚才读了这些cmets。我已经勾选了答案。但是,我确实赞成您的回答。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2011-10-22
  • 1970-01-01
  • 1970-01-01
  • 2021-04-06
  • 1970-01-01
  • 1970-01-01
  • 2012-04-15
  • 1970-01-01
相关资源
最近更新 更多