模板:Time:修订间差异
更多操作
建立内容为“<includeonly>{{#invoke:time|time|{{{1|}}}|{{{2|}}}}}</includeonly><!-- --><noinclude> {{Documentation}} </noinclude>”的新页面 |
简化 |
||
| 第1行: | 第1行: | ||
<includeonly>{{#invoke:time|time|{{{1|}}}|{{{2|}}}}}</includeonly | <includeonly>{{#invoke:time|time|{{{1|}}}|{{{2|}}}}}</includeonly><noinclude> | ||
{{Documentation}} | {{Documentation}} | ||
</noinclude> | </noinclude> | ||
2022年6月11日 (六) 20:01的最新版本
该模板在参数指定的时区中显示当前时间。该时间是根据指定时区相对于UTC的偏移量, 并考虑到夏令时在该时区当前是否启用。
注意: 大多数页面显示页面的缓存版本以减少服务器负载, 因此模板仅显示 "自上次解析页面时起" 的当前时间。您可以通过单击 [刷新] 链接刷新显示的时间。
参数
{{time}} 支持两个位置参数和几个命名参数; 皆为可选的:
- 列表
|<time zone>– 第一个定位 (未命名) 参数, 指定模板要为其提供时间输出的时区。如果省略, 则模板显示UTC时间。时区通过时区标准时间名称的缩写来标识。不要使用夏季或夏令时的缩写; 它们将被忽略并产生错误消息。|<df>–|df=的位置 (未命名) 版本,请参见|df=– 日期格式; 该参数采用多个值之一; 除此以外的值将被忽略:|df=dmy– 指定为日月年格式; 时间为24小时制; 别名:|df=dmy24|df=dmy12– 与|df=dmy相同, 除了时间格式为12小时上午/下午|df=mdy– 指定为月日年格式; 时间为24小时制; 如果在时区的属性中未指定日期格式, 则为默认值; 别名:|df=mdy24|df=dmy12– 与|df=mdy相同, 除了时间格式为12小时上午/下午|df=iso– 以大致符合ISO 8601标准的格式呈现日期/时间 (省略秒?)|df=y– 旧{{time}}参数, 与|df=dmy相同。|df=12– 仅时间显示12小时上午/下午格式|df=24– 仅时间显示24小时格式
|df-cust=– 使用在mw:Help:Extension:ParserFunctions##time处定义的代码自定义时间/日期格式; 产生|df=|dst=– 设置为no时, 将禁用时区的夏令时计算; 其他值被忽略; 对于时区中未遵守夏令时的位置很有用; 例如Arizona|lang=<代码>– 以ISO 639语言<代码>指定的语言显示时间/日期- 这些参数仅接受值
yes|dateonly=– 取消时间显示|timeonly=– 取消日期显示|hide-refresh=– 取消刷新链接|hide-tz=– 取消时区缩写显示|unlink-tz=– 以未链接的形式显示时区缩写
|_TEST_TIME_=– 在模板代码的开发过程中有用的参数。分配给此参数的值必须是ISO 8601格式, 没有时区指示符 (2026-03-14T15:50:08) 或YYYYMMDDhhmmss格式。模板将其解释为UTC。
使用
通常, 所需要做的只是:
更改渲染格式:
{{time|MST|df=y}}{{time|MST|y}}{{time|MST|dmy}}{{time|MST|iso}}
支持的时区
这是当前支持的时区缩写的列表:
- ACST (ACDT)
- AEST (AEDT)
- AKST (AKT)
- AoE[stz-fn 1]
- AST (AT) (ADT)
- AWST
- BST
- BJT [stz-fn 2]
- CET (CEST)
- ChST
- CST (CT) (CDT)
- EET (EEST)
- EST (ET) (EDT)
- GMT
- GMT-IE[stz-fn 3]
- GMT-UK[stz-fn 4]
- HAST (HADT) (HST) (HDT)
- IDLE[stz-fn 1]
- IDLW[stz-fn 1]
- IRKT
- IST
- JST
- KRAT
- MSK
- MST
- NST
- NZST (NZDT)
- OMST
- PETT
- PKT
- PMST[stz-fn 5]
- PST (PT) (PDT)
- SAMT
- SAST
- SRET
- SST
- USZ1
- UTC
- VLAT
- WET (WEST)
- WGT[stz-fn 6]
- WIB
- WIT
- WITA
- YAKT
- YEKT
- ↑ 1.0 1.1 1.2 非标准时区, 这些都是程序员的一时兴起; AoE 是 'Anywhere on Earth', 'IDLE' 和 'IDLW' 是 国际如期变更线 (International Date Line) 东/西
- ↑ 北京时间 (Beijing Time), 国际上使用的名称缩写为CST (China Standard Time, 中国标准时间), 但其与 (Central Standard Time, 北美中部时间) 混淆, 正在征求改善意见。
- ↑ 爱尔兰标准时间. IST 这个缩写也被用于 印度标准时间。爱尔兰标准时间发生在夏天。由于这些原因, 该模板使用GMT-IE作为爱尔兰的时区缩写。
- ↑ 格林威治时间不遵守夏令时。英国在冬季遵守格林尼治标准时间, 但在夏季改为英国夏令时。BST的缩写也被孟加拉标准时间使用。要区分英国的GMT和全年的GMT,请使用GMT-UK。
- ↑ 圣皮埃尔和密克隆标准时间
- ↑ 西格陵兰时间
UTC 偏移值
要显示特定UTC偏移值的时间, 请指定UTC时间偏移值作为时区:
{{time|UTC-07:00}} → 2026-03-14T08:50 UTC−07:00 [刷新]
需要'UTC', 符号字符, 两个小时数字, 一个冒号和两个分钟数字。可接受的符号字符为: "+", "-" (连字符) , "±" 和 "-" (减号)。
军事/航海时区
要显示特定军事或航海时区[1], 使用时区的alpha标识:
{{time|M}} → 2026-03-15T03:50 M [刷新]
某些军事和航海时区标记带有星号 (*) , 剑标 (†) 或双剑标 (‡) 。要显示它们, 分别使用 "+" 和 "++" :
{{time|M++}} → 2026-03-15T04:35 M‡ [刷新]
{{time|M+}} → 2026-03-15T05:50 M† [刷新]
夏令时
夏令时 (DST) 的计算对于观察到的那些时区是自动的。在通常观察到的时区中, 有些地区没有观察到DST。要为非观察区域设置正确的时间, 请设置|dst=no:
{{time|MST|dst=no}} → 08:50, 3月 14, 2026 MST [刷新] – 亚利桑那州中的时间
{{time|MST}} → 09:50, 3月 14, 2026 MDT [刷新] – 亚利桑那州中纳瓦霍族保留地的时间
不支持相反的情况。对于格陵兰的图勒空军基地这样的地方, 它遵循美国DST规则, 而WGT则遵循欧洲DST规则, 因此Module:Time中将需要一个时区属性表。请参阅§[[#添加新时区|]]。
错误消息
{{time}} 可以产生几个错误信息。它们是:
- {{time}} – 参数 |df-cust-a= 和 |df-cust-p 都是必须的 – 在定义am (或pm) 时间的自定义格式时, 还必须定义pm (或am) 时间的自定义格式。
- {{time}} – 计算DST时间戳时出错 – 表示内部错误, 因为以下一个或多个时区属性格式错误: UTC偏移, DST开始或结束定义。要解决此错误, 请确保时区的属性正确。
- {{time}} – ... 的定义不完整 – 表示内部错误, 因为缺少以下一个或多个时区属性: DST开始或结束定义, DST事件时间, 时区条目。要解决此错误, 请提供缺少的属性。
- {{time}} – 日期格式无效: <format> – 分配给
|df=的值不是定义的格式字符串之一; §参数。 - {{time}} – ± 的无效使用 - 当分钟和小时偏移量不是00:00时使用符号±。
- {{time}} – 异常或不完整的 _TEST_TIME_ – 分配给此参数的值的格式必须为:
YYYY-MM-DDThh:mm:ss, 其中除 "T" 外的所有数字都是数字, 或者为YYYYMMDDhhmmss。 - {{time}} – 未知时区 – 时区位置参数不是支持的时区缩写之一。要解决此错误, 请检查参数的拼写或将时区的属性添加到模块中。请参阅§[[#添加新时区|]]。
添加新时区
{{time}} 使用 Module:Time/data。该模块是一个表格表, 该数据结构指定各个时区的属性。空白的时区属性表具有以下形式:
[''] = {
abbr = '',
dst_abbr = '',
utc_offset = '',
df = '',
dst_begins = '',
dst_ends = '',
dst_time = '',
dst_e_time = '',
article = ''
},
To add a new time zone to 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:
['']– (required) the abbreviation of a time zone's standard time; must be lower case; this is the value that will be used in the template's time zone parameterabbr = ''– (required) the abbreviation of a time zone's standard time as it will be rendered by the templatedst_abbr = ''– the abbreviation of a time zone's daylight saving or summer time as it will be rendered by the templateutc_offset = ''– (required) the offset in hours and minutes from wikipedia:UTC±00:00; has the form:utc_offset = '<sign>hh:mm'where<sign>may be+(optional) or-(required for time zones west of the 0 meridian)df = ''– one of three keywordsdmy,mdy, orisoused to specify date format typically used in the time zone; can be overridden with|df=template parameterdst_begins = ''– a four word sentence in the form<ordinal><day name><in|of><month name>where:<ordinal>– any of the words 'first', '1st', 'second', '2nd', ... 'fifth', '5th', or 'last'<day name>– any of the day names 'Sunday', 'Monday', 'Tuesday', etc.; capitalization is not important but otherwise must be spelled correctly; abbreviations not supported<in|of>– either of the words 'in' or 'of'<month name>– any of the month names 'January', 'February', 'March', etc.; capitalization is not important but otherwise must be spelled correctly; abbreviations not supported
dst_ends = ''– (required ifdst_beginsis specified) same asdst_beginsdst_time = ''– (required ifdst_beginsis specified) the time that daylight saving time begins; usually local time; when DST begins at a specified time UTC (wikipedia:European Summer Time for example) use:dst_time = 'hh:mm UTC'; four digits and the colon are requireddst_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 requiredarticle = ''– (required) the title of a Wikipedia article that is appropriate to the timezone; 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.
添加新别名
You may also want to add an alias of a timezone:
[''] = {tz = ''},
To add a new time zone to 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.
模板数据
无描述。
| 参数 | 描述 | 类型 | 状态 | |
|---|---|---|---|---|
| 时区 | 1 | 时间格式的时区
| 字符串 | 推荐 |
| 日期格式 | 2 df | 呈现日期和时间的格式
| 未知 | 推荐 |
| 夏令时 | dst | 无描述
| 字符串 | 可选 |
| ISO 639 语言代码 | lang | 以ISO 639语言指定的语言显示时间/日期 | 字符串 | 可选 |
| dateonly | dateonly | 如果为 'yes' ,则不显示时间, 仅显示日期
| 字符串 | 可选 |
| timeonly | timeonly | 如果为 'yes' ,则不显示日期, 仅显示时间
| 字符串 | 可选 |
| 隐藏时区? | hide-tz | 如果为 'yes' , 则不显示时区缩写
| 字符串 | 可选 |
| 不链接到时区? | unlink-tz | 如果为 'yes', 呈现时区而不链接到其在Wikipedia中的条目
| 字符串 | 可选 |
脚注
- ↑ World Time Zone Map HM Nautical Almanac Office February 2016