本页使用了标题或全文手工转换

Template:Time

维基百科,自由的百科全书
跳到导航 跳到搜索
文档图示 模板文档[查看] [编辑] [历史] [清除缓存]


概要[编辑]

本模板顯示由參數值指定的時區的現在時間,由該時區的UTC offset計算出來,如果該時區當時正在實施夏令時間,也會相應調整。

注意:為減輕伺服器負荷,大多數條目頁面顯示該頁面的緩存版本,所以該版本顯示的「現在時間」可能已經過時。您可以點擊[刷新]連結來更新現在時間。

參數[编辑]

{{time}} supports two positional and several named parameters; none are required:

|<time zone> – the first positional (unnamed) parameter, specifies the time zone for which the template is to provide a time output. If omitted, the template displays UTC time. A time zone is identified by an abbreviation of the time zone's standard-time name. Do not use a summertime or daylight saving time abbreviation; they will be ignored and produce an error message.
|<df> – the positional (unnamed) version of |df= which see
|df= – date format; this parameter takes one of several values; values other than these are ignored:
|df=dmy – specifies day month year date format; time in 24-hour format; alias: |df=dmy24
10:56, 28 9月 2020 MDT [刷新]
|df=dmy12 – same as |df=dmy except time in 12-hour am/pm format
10:56 am, 28 9月 2020 MDT [刷新]
|df=mdy – specifies month day, year format; time in 24-hour format; default when a date format is not specified in the time zone's properties; alias: |df=mdy24
10:56, 9月 28, 2020 MDT [刷新]
|df=mdy12 – same as |df=mdy except time in 12-hour am/pm format
10:56 am, 9月 28, 2020 MDT [刷新]
|df=iso – renders the date/time in a form roughly adhering to the ISO 8601 format (seconds omitted)
2020-09-28T10:56 MDT [刷新]
|df=y – legacy {{time}} parameter, same as |df=dmy
|df=12 – time-only display 12-hour am/pm format
10:56 am MDT [刷新]
|df=24 – time-only display 24-hour format
10:56 MDT [刷新]
|df-cust= – custom time/date formats using the codes defined at mw:Help:Extension:ParserFunctions##time; yields to |df=
|df-cust-a= – custom time/date formats as above specifically for ante meridiem time; requires |df-cust-p=; yields to |df-cust=
|df-cust-p= – custom time/date formats as above specifically for post meridiem time; requires |df-cust-a=; yields to |df-cust=
|dst= – when set to no, disables the daylight saving time calculation for the time zone; other values ignored; useful for locations within a time zone that do not observe daylight saving time; Arizona, for example
|lang=<code> – displays time/date in language specified by ISO 639 language <code>
these parameters take only the value yes:
|dateonly= – suppresses time display
|timeonly= – suppresses date display
|hide-refresh= – suppresses the refresh link
|hide-tz= – suppresses the timezone abbreviation
|unlink-tz= – renders unlinked timezone abbreviation
|_TEST_TIME_= – a parameter that was useful during the development of the template's code. The value assigned to this parameter must either be in ISO 8601 format without time zone designator (2020-09-28T16:56:55), or YYYYMMDDhhmmss format as output by {{Timestamp}} (Template:Timestamp). This is interpreted by the template as UTC.

用法[编辑]

Typically, all that is needed is:

{{time|<TZ>}} where <TZ>是支持的時區縮寫
{{time|MST}}
2020年9月28日 10:56 MDT [刷新]

To change the rendered format:

{{time|MST|df=y}}
10:56, 28 9月 2020 MDT [刷新]
{{time|MST|y}}
10:56, 28 9月 2020 MDT [刷新]
{{time|MST|dmy}}
10:56, 28 9月 2020 MDT [刷新]
{{time|MST|iso}}
2020-09-28T10:56 MDT [刷新]

支持的時區[编辑]

This is a list of the currently supported time zone abbreviations:

  1. ^ 1.0 1.1 1.2 Not standard time zones, these are included on a whim of the programmer; AoE is 'Anywhere on Earth', 'IDLE' and 'IDLW' are International Date Line East and West
  2. ^ Irish Standard Time. The abbreviation, IST, is also used for Indian Standard Time. Irish Standard Time occurs in the summer. For these reasons, the template uses GMT-IE as the time zone abbreviation for Ireland.
  3. ^ GMT does not observe daylight saving time. In the United Kingdom GMT is observed in winter but shifts to British Summer Time. The abbreviation BST is also used by Bangladesh Standard Time. To differentiate year-round GMT from GMT as observed in the UK, use GMT-UK.
  4. ^ Saint-Pierre and Miquelon Standard Time
  5. ^ Western Greenland Time

UTC offset[编辑]

To display the time at a particular UTC offset, specify the UTC time offset as the time zone:

{{time|UTC-07:00}}
2020-09-28T09:56 UTC−07:00 [刷新]

'UTC', a sign character, two hour digits, a colon, and two minute digits are required. Accepted sign characters are: '+', '-' (hyphen), '±', and '−' (minus).

Military/nautical time zones[编辑]

To display the time at a particular military or nautical time zone,[1] use the time zone's alpha designation:

{{time|M}}
2020-09-29T04:56 M [刷新]

Some military and nautical time zone designators are extended with an asterisk (*), a dagger (†), or double dagger (‡). When writing this template for designators that are extended with a dagger or double dagger, use '+' and '++' respectively:

{{time|M++}}
2020-09-29T05:41 M‡ [刷新]
{{time|M+}}
2020-09-29T06:56 M† [刷新]

夏令時間[编辑]

Daylight saving time (DST) calculations are automatic for those time zones where it is observed. 有些時區在實施夏令時間時,當中若干地區不跟隨,在這些不使用夏令時間的地區可以使用|dst=no

{{time|MST|dst=no}}
2020年9月28日 09:56 MST [刷新]time in Arizona
{{time|MST}}
2020年9月28日 10:56 MDT [刷新] – but, time on the Navajo Nation in Arizona

The opposite case is not supported. For places like Thule Air Base in Greenland, which observes US DST rules while WGT observes EU DST rules, a time zone properties table will be needed in Module:Time. See §Adding a new time zone.

錯誤訊息[编辑]

{{time}}可以產生以下錯誤訊息,包括:

{{time}} – both of |df-cust-a= and |df-cust-p required – when defining a custom format for am (or pm) time, you must also define a custom format for pm (or am) time
{{time}} – error calculating dst timestamps – indicates an internal error because one or more of the following time zone properties is malformed: UTC offset, DST begin or end definition. To resolve this error make sure that the time zone's properties are correct.
{{time}} – incomplete definition for ... – indicates an internal error because one or more of the following time zone properties is missing: DST begin or end definition, DST event time, time zone article. To resolve this error supply the missing properties.
{{time}} – invalid date format <format> – value assigned to |df= is not one of the defined format strings; ss §Parameters
{{time}} – invalid use of ± - 符號±被用於the minute and hour offsets不是00:00的情形
{{time}} – malformed or incomplete _TEST_TIME_ – value assigned to this parameter must either have the format: YYYY-MM-DDThh:mm:ss where all except 'T' are digits, or YYYYMMDDhhmmss
{{time}} – unknown timezone – 填入的time zone positional parameter不是支持的時區縮寫。To resolve this error check the parameter's spelling or add the time zone's properties to the module. 見§加入新時區

加入新時區[编辑]

{{time}}使用Module:Time/data。這是一個有多個表格的表格,the data structure that specifies the properties of the individual time zones。空白的時區properties table有以下格式:

[''] = {
	abbr = '',			
	dst_abbr = '',
	utc_offset = '',
	df = '',
	dst_begins = '',
	dst_ends = '',
	dst_time = '',
	dst_e_time = '',
	article = ''
},

在Module:Time/data加入一個新時區,add the appropriate information inside the single quotes. If a property does not apply, leave the quotes empty. The rules for each property are:

[''] – (必填)一個時區標準時間的縮寫,小寫;this is the value that will be used in the template's time zone pararameter
abbr = '' – (必填)the abbreviation of a time zone's standard time as it will be rendered by the template
dst_abbr = '' – 一個時區的夏令時間的縮寫 as it will be rendered by the template
utc_offset = '' – (必填)the offset in hours and minutes from UTC±00:00;採用以下格式:utc_offset = '<sign>hh:mm' where <sign> may be + (optional) or - (required for time zones west of the 0 meridian)
df = '' – one of three keywords dmy, mdy, or iso used to specify date format typically used in the time zone; can be overridden with |df= template parameter
dst_begins = '' – a four word sentence in the form <ordinal> <day name> <in|of> <month name> where:
<ordinal> – 'first', '1st', 'second', '2nd', ... 'fifth', '5th', 或 'last'的其中一個
<day name> – 'Sunday', 'Monday', 'Tuesday', etc.的其中一個;capitalization is not important but otherwise must be spelled correctly;不支持縮寫
<in|of> – 'in' 或 'of'的其中一個
<month name> – 月份名'January', 'February', 'March', etc.的其中一個;capitalization is not important but otherwise must be spelled correctly;不支持縮寫
dst_ends = '' – (required if dst_begins is specified) same as dst_begins
dst_time = '' – (required if dst_begins is specified) the time that daylight saving time begins; usually local time; when DST begins at a specified time UTC (European Summer Time for example) use: dst_time = 'hh:mm UTC'; four digits and the colon are required
dst_e_time = '' – the time that daylight saving time ends if different from the time it begins; usually local daylight saving time ; when DST ends at a specified time UTC use: dst_e_time = 'hh:mm UTC'; four digits and the colon are required
article = '' – (必填)該時區的條目名;do not include wikimarkup

The table-of-tables is organized east (plus UTC offsets) then west (minus UTC offset), by offset hours, and then alphabetically by time zone positional parameter name.

加入新alias[编辑]

You may also want to add an alias of a timezone:

[''] = {tz = ''},

在Module:Time/data加入新時區,add the appropriate information inside the single quotes.

[''] – (required) the abbreviation of a time zone's alias. This must be lower case.
tz = '' – (required) the abbreviation of the time zone that's already in the code. This must be lower case

The table-of-tables is organized east (plus UTC offsets) then west (minus UTC offset), and by if it's a DST offset or if it's not.

See also[编辑]

Template:Date and time templates

References[编辑]

  1. ^ World Time Zone Map. HM Nautical Almanac Office. February 2016. 


模板编辑说明[编辑]

无描述。

模板参数

参数说明类型状态
time zone1

The time zone for the time formatting

例子
EST
字符串推荐
date format2df

The format to render the date and time

例子
dmy12
未知推荐
Daylight savings timedst

无描述

例子
yes
字符串可选
ISO 639 language codelang

displays time/date in language specified by ISO 639 language

字符串可选
Dateonlydateonly

If 'yes', suppresses display of the time and only shows the date

例子
yes
字符串可选
Timeonlytimeonly

If 'yes', suppresses display of the date and only shows the time

例子
yes
字符串可选
Hide time zone?hide-tz

If 'yes', suppresses time zone abbreviation

例子
yes
字符串可选
Don't link time zone?unlink-tz

If 'yes', renders the timezone without linking to its article.

例子
yes
字符串可选

參見[编辑]