模板:Time interval

模板页面
文档图示 模板文档[查看] [编辑] [查看历史] [清除缓存]

使用说明

这个模板会自动计算两个日期间相隔的时间。请注意,此模板使用公历纪年,日期支持范围从公元前9999年至公元9999年。

Syntax

  • 错误:第一个参数中的开始日期无效

There are two positional arguments: date1 and date2. The default for each is the current date and time.

The result displays text representing the time interval from date1 to date2 (date2date1).

Dates are UTC—local times and time zones are not supported.

Dates are checked for validity. For example, 29 February 2000 is accepted, but 29 February 1900 is not a valid date.

Each date can include an era or a time, and a variety of formats are accepted. Examples of valid dates are:

1900-02-01
1900-2-1
1900-02-01 14:45
1 FEB 1900
February 1, 1900
February 1 1900 14:45
2:45 pm February 1 1900
1 February 1900 2:45 p.m.
BC 1 Feb 120

Examples:

  • {{time interval|1 Jan 2001|March 4, 2002}} → 1年2个月又3天
  • {{time interval|1 Jan 2001|March 4, 2002|abbr=on}} → 1y2m零3d
  • {{time interval|B.C.E. 1 Feb 120|28 FEB 1900}} → 2019年27天

Parameters

Parameter Description
abbr=off Unit names in full (default): year, month, day, hour, minute.
abbr=on Units shown as a single letter with no space between number and unit: y, m, d, h, m.
disp=age If no show has been entered, years are displayed if the age is above 3 years, years and months from 1 to 3 years, or months and days for under 1 year. Sets sep=space by default. This is compatible with 模板链接:{{age for infant}}.
disp=raw Display numbers only with sep=space.
duration=on Period is a duration (has an extra day to include the end date).
format=commas Numbers over 999 are formatted with commas.
format=raw Use a hyphen (-) to indicate a negative date difference instead of a minus (−); a hyphen may allow the result to be used in a calculation.
sep=comma Separator between items is a comma: 1 year, 2 months, 3 days. The default is 1 year, 2 months and 3 days.
sep=, Same as sep=comma.
sep=serialcomma Use a serial comma: 1 year, 2 months, and 3 days.
sep=space Use a space: 1 year 2 months 3 days.
sc=y Change the default separator to use a serial comma. Also accepts sc=yes and sc=on.
show=y years
show=ym years and months
show=ymd years, months and days (default)
show=ymw years, months and weeks
show=ymwd years, months, weeks and days
show=yd years and days
show=m months
show=md months and days
show=w weeks
show=wd weeks and days
show=d days
show=dh days and hours
show=dhm days, hours and minutes
show=dhms days, hours, minutes and seconds
show=ymdh ymd + hours
show=ymdhm ymd + hours and minutes
show=ymwdh ymwd + hours
show=ymwdhm ymwd + hours and minutes
show=h hours (result would be 48 hours for a difference of 2 days)
show=hm hours and minutes
show=hms hours, minutes and seconds
round=on Round the least-significant unit specified with the show= parameter.
round=months Round to nearest month using show=ym.
round=weeks Round to nearest week using show=ymw.
round=days Round to nearest day using show=ymd.
round=hours Round to nearest hour using show=ymdh.
sortable=on Output a hidden sort key based on the number of days in the date difference (includes a fraction of a day to handle time differences).
sortable=off No sort key (default).
sortable=debug Output a visible sort key for testing.
上述文档内容嵌入自Template:Time interval/doc编辑 | 历史
编者可以在本模板的沙盒创建 | 镜像和测试样例创建页面进行实验。
请将模板自身所属的分类添加在文档中。本模板的子页面