Jump to content

手册:时区

From mediawiki.org
This page is a translated version of the page Manual:Timezone and the translation is 53% complete.
Outdated translations are marked like this.

未指定自定义偏移的用户的默认时区(tz)可被手动配置。

Default value

The default value is taken from the webserver configuration (PHP ini file). For documentation:

https://www.php.net/datetime.configuration#ini.date.timezone

主要方法

  • 在您的安装目录中创建一个$LocalSettings的备份副本
  • 编辑LocalSettings.php文件并添加以下代码:
#设置默认时区
$wgLocaltimezone = "Asia/Jakarta";
date_default_timezone_set( $wgLocaltimezone );
$wgLocaltimezone = "UTC";
$wgLocaltimezone = "Europe/London";
$wgLocaltimezone = "Asia/Taipei";
此时区将被用于:
  • ~~~~签名
  • 最近更改中的时间戳
  • 历史中的时间戳
添加这些代码到LocalSettings.php与Extension:RSS 中RSS订阅的日期相冲突。 请参阅Extension:RSS的讨论页面以获取更多信息。

替代方法

此方法已经在首要方法无法使用的条件下被多位用户验证过。

$wgLocaltimezone = "America/Sao_Paulo";
$dtz = new DateTimeZone($wgLocaltimezone);
$dt = new DateTime('now', $dtz);
$wgLocalTZoffset = $dtz->getOffset($dt) / 60;
unset($dtz);
unset($dt);

具体替代方法

If you just want to use the local time of your PC, you can add this line in your LocalSettings.php. This method is what MediaWiki does by default (see includes/Setup.php); it also avoids problems with daylight savings time:

$wgLocalTZoffset = date("Z") / 60;

未确认方法

  • To use your local time zone (say NZDT) put this in LocalSettings.php
$wgLocalTZoffset = 13 * 60;

  • This example may also work
$wgLocaltimezone="Europe/Berlin";
$wgLocalTZoffset = +120;
  • In this case the primary method did not take daylight savings time into account. The example below works:
#设置默认时区
$wgLocaltimezone = "Europe/Amsterdam";

#Calculate the timezone offset with UTC
$oldtz = getenv("TZ");
putenv("TZ=$wgLocaltimezone");
$wgLocalTZoffset = date("Z") / 60 + date("I") * 60;
putenv("TZ=$oldtz");

  • To make it work in 1.5.8, specify the offset in hours, so change all occurrences of '/ 60' to '/ 3600', for example.
$wgLocaltimezone = "Europe/Amsterdam";
#Calculate the timezone offset with UTC
$oldtz = getenv("TZ");
putenv("TZ=$wgLocaltimezone");
$wgLocalTZoffset = date("Z") / 3600;
putenv("TZ=$oldtz");

Combine it with the tip above to make daylight savings work.

  • This line is needed in 1.16. It applies to both anonymous and logged in users.

Note that you will need to provide the correct values if you want the zone to be selected by default in the timezone dropdown:

$wgDefaultUserOptions['timecorrection'] = 'ZoneInfo|' . (date("I") ? 120 : 60) . '|Europe/Berlin';
The methods in this section are unconfirmed and may not work properly.

手动时区规格

The primary method needs the server to support the 'tz' database; some non-GNU hosts don't do that. However you can supply timezone data manually - unfortunately, only "GMT0" seems to work on Windows.

例如使用

$wgLocaltimezone = "CET-1CEST-2,M3.5.0/2,M10.5.0/2";
而不是
$wgLocaltimezone = "Europe/Budapest";
$wgLocaltimezone = "AEST-9,M10.5.0/3,M4.1.0/3";
而不是
$wgLocaltimezone = "Australia/Sydney";

更多详情请参见