我在 debian 8 上使用 php 5.6.17。设置 owncloud 后,我注意到,
由 owncloud(不是由 apache)自行编写的日志具有错误的时区。
我对此进行了一些调查,似乎该行:
DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", ""), 'Europe/Berlin');
这不关心任何时区设置。而不是欧洲/柏林 (+1/+2) 的时间,我总是得到 UTC 的时间。
在
/etc/php5/apache2/php.ini
我设置了"date.timezone = "Europe/Berlin"
并且系统时间(debian)也是正确的。即使我运行类似下面的东西,我也会得到相同的输出(UTC):
$time=DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), new DateTimeZone('UTC'));
echo $time->format('c') . "\n";
$time=DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), new DateTimeZone('Europe/Berlin'));
echo $time->format('c') . "\n";
关于这个问题的任何想法?
最佳答案
引用 PHP manual on DateTime::createFromFormat() :
Note: The timezone parameter and the current timezone are ignored when the time parameter either contains a UNIX timestamp (e.g. 946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).
如果要更改时区,则必须使用 setTimezone()创建对象后的方法。
关于php 时区:DateTime::createFromFormat 忽略时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36200360/