【问题标题】:How to convert PDT time format to this format `2016-09-13 08:56:55 +0000` - using PHP?如何将 PDT 时间格式转换为这种格式 `2016-09-13 08:56:55 +0000` - 使用 PHP?
【发布时间】:2016-09-13 11:21:37
【问题描述】:

这个字符串2016-09-13 08:56:55 +0000 - 时区是什么?

如何将 PDT 时间格式 Wed Oct 12 14:40:50 PDT 2016 转换为该格式 2016-09-13 08:56:55 +0000.

我试试:

$input_datetime = 'Wed Oct 12 14:40:50 PDT 2016';
$result_datetime = date('Y-m-d H:i:s',strtotime($input_datetime)) . ' +0000';
echo $result_datetime; // 2016-10-12 14:40:50 +0000

我不知道timezones。只是我正在制作datetime 格式。 请更新解决方案或建议。 谢谢大家!

【问题讨论】:

  • +0000 是时区。你的转换毫无意义。为什么分钟和秒会发生变化?
  • 抱歉,我不知道timezones。只是我正在制作datetime 格式。

标签: php datetime timezone


【解决方案1】:

您的预期输出对我来说没有意义,因为提到 nogad 行,秒和分钟会发生变化。请说清楚。同时这里是你想要的转换格式:

$datestr = 'Wed Oct 12 14:40:50 PDT 2016';
$dt = new DateTime($datestr);
echo $dt->format("Y-m-d\ H:i:s O");

输出是:

2016-10-12 14:40:50 -0700

【讨论】:

  • -0700是什么意思?
  • 这是时区修饰符。这是与格林威治时间 (GMT) 的时差。
  • 谢谢!为您提供帮助。
猜你喜欢
  • 2021-09-23
  • 2016-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-20
  • 1970-01-01
  • 1970-01-01
  • 2017-03-04
相关资源
最近更新 更多