我试图得到正确的时间用PHP不是用户的计算机会在那里,让正确的“GMT”时间例的功能之一。
PHP获取服务器日期,而不是用户计算机的日期。
如果你需要得到一个不同的日期时区,那么你需要的时区设置为你想要的。
请参阅:http://php.net/manual/en/function.date.php
喜欢:
$tz = 'Europe/London';
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('d.m.Y, H:i:s');
您将只得到服务器的时间,而不是电脑的时间
$now = new DateTime(null, new DateTimeZone('America/New_York')); //timezone format
echo $now->format("Y-m-d\TH:i:sO"); // Server time