PHP datetime转换给了我错误的时间

时间:2018-04-28 20:33:00

标签: php

我正在将08/22/2015 10:56 PM CST转换为UTC

转化

  • 10:56 PM CST = 3:56 AM UTC
  • 因此日期应为:2015-08-23 03:56:00 +04

  • 以下代码给我:2015-08-23 04:56:00 +04(不正确)

Repl中的代码 https://repl.it/repls/LovelyKhakiExtension

    $datetime = '08/22/2015 10:56 PM';
    $tz_from = 'CST';
    $tz_to = 'UTC';
    $format = 'Y-m-d H:i:s +h';

    $dt = new DateTime($datetime, new DateTimeZone($tz_from));
    $dt->setTimeZone(new DateTimeZone($tz_to));
    echo $dt->format($format) . "\n";

0 个答案:

没有答案