-
一只甜甜圈
时间会根据你的服务器时间。解决此问题的一个简单方法是手动设置时区,方法是使用date_default_timezone_set在date()或time()函数被调用到。我在墨尔本,澳大利亚所以我有这样的东西:date_default_timezone_set('Australia/Melbourne');或者另一个例子是洛杉矶-我们:date_default_timezone_set('America/Los_Angeles');您还可以看到服务器当前位于VIA中的时区:date_default_timezone_get();所以就像:$timezone = date_default_timezone_get();echo "The current server timezone is: " . $timezone;因此,你的问题的简短答案是:// Change the line below to your timezone!date_default_timezone_set('Australia/Melbourne');$date = date('m/d/Y h:i:s a', time());那么所有的时间都会转到您刚刚设置的时区:)
-
DIEA
// Simply:$date = date('Y-m-d H:i:s');// Or:$date = date('Y/m/d H:i:s');// This would return the date in the following formats respectively:$date = '2012-03-06 17:33:07';// Or$date = '2012/03/06 17:33:07';/** * This time is based on the default server time zone. * If you want the date in a different time zone, * say if you come from Nairobi, Kenya like I do, you can set * the time zone to Nairobi as shown below. */date_default_timezone_set('Africa/Nairobi');// Then call the date functions$date = date('Y-m-d H:i:s');// Or$date = date('Y/m/d H:i:s');// date_default_timezone_set() function is however// supported by PHP version 5.1.0 or above.
-
慕村225694
因为PHP5.2.0你可以用OOP和DateTime()当然,如果您喜欢OOP,也可以:$now = new DateTime();echo $now->format('Y-m-d H:i:s'); // MySQL datetime formatecho $now->getTimestamp();
// Unix Timestamp -- Since PHP 5.3并指定timezone:$now = new DateTime(null, new DateTimeZone('America/New_York'));$now->setTimezone(new DateTimeZone('Europe/London'));
// Another wayecho $now->getTimezone();