php dateTime逻辑错误?

时间:2017-04-21 03:15:11

标签: php datetime

我正在编写一个基本的时钟和日历,以便在不和谐的情况下播放正在进行的桌面RPG。游戏中的时间移动速度是实时的两倍。这场比赛是在底特律举行的。通用汽车已经裁定现实世界中的2017年2月25日相当于游戏世界中的25/08/2008。 在我的代码中我知道两个问题。

  1. 最终可能会跳过偶数天。我还没有能够验证这一点。
  2. 时钟似乎按预期工作,但日期快了八天。
  3. 感谢任何反馈。

    <?php
    //game start and current date
    $start = new DateTime('2017-02-25T00:00:00.000000Z');
    echo $start->format('Y-m-d H:i:s');
    echo "\r\n";
    $current = new DateTime("now", new DateTimeZone('America/Detroit') );
    echo $current->format('Y-m-d H:i:s');
    echo "\r\n";
    //find the difference
    $difference = $start->diff($current);
    echo $difference->format('%R%a days');
    echo "\r\n";
    
    //take the starting time in-game
    $d = new DateTime('2008-08-25T00:00:00.000000Z');
    echo $d->format('Y-m-d H:i:s');
    
    //add the difference twice to get current gameTime
    $d->add($difference);
    $d->add($difference);
    echo "\r\n";
    
    // Output the date with microseconds.
    echo $d->format('Y-m-d H:i:s');
    echo "\r\n";
    
    ?>
    

0 个答案:

没有答案