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