Template:Extract
此模板使用Lua语言: |
本模板可以從日期中提取相關資訊,或者可以將日期格式化。時間單位可以加入至日期當中。
參數
{{extract|日期|選填參數}}
以下為選擇參數:
add=periods to add
• 增加/減少時間單位。fix=on
• 調整無效的時間單位。partial=on
• Accept a year only, or a year and month only.show=顯示格式
• 指定應該要提取的資訊(如dayname
)或顯示日期的格式(如mdy
)。sortable=on
• A hidden sort key is inserted before the date (for use in sortable tables).
在第1個參數中,可以輸入日期,或是依照年/月/日/時/分/秒之順序拆分成獨立參數。
日期的顯示預設為DMY格式,舉例:
{{extract|2015-11-12}}
→ 12 November 2015
日期
A valid date must be specified. Dates are UTC—local times and time zones are not supported.
Dates from 9999 BCE to 9999 CE are accepted. The proleptic Gregorian calendar is used by default. Entering the parameter julian
with a date uses the proleptic Julian calendar.
A date can include an era or a time, and a variety of formats are accepted.
Examples of valid dates follow. Each row shows two equivalent methods of entering a date.
A date as a single parameter | Components of a date in separate parameters |
---|---|
{{extract|1900-02-01}} |
{{extract|1900|02|01}}
|
{{extract|1900-2-1 14:45}} |
{{extract|1900|2|1|14|45}}
|
{{extract|1 FEB 1900}} |
{{extract|1900|FEB|1}}
|
{{extract|February 1, 1900}} |
{{extract|1900|February|1}}
|
{{extract|Feb 1 1900 14:45}} |
{{extract|1900|Feb|1|14|45}}
|
{{extract|2:45 pm February 1 1900}} |
{{extract|1900|February|1|14|45}}
|
{{extract|1 February 1900 2:45 p.m.}} |
{{extract|1900|February|1|14|45}}
|
{{extract|BC 1 Feb 120}} |
{{extract|-119|2|1}}
|
The last example above uses the rule:
- n BC is year 1 − n
Year 0 refers to 1 BC, and year −1 is 2 BC, etc.
Dates can also be entered with the following special names which are not case sensitive.
{{extract|juliandate|2451545}}
→ 1 January 2000 (Julian day 2451545 is noon 1 January 2000 UTC in the Gregorian calendar){{extract|juliandate|julian|2451545}}
→ 19 December 1999 (which is 19 December 1999 in the Julian calendar){{extract|currentdate}}
→ 24 October 2024 (the date shown is when this documentation page was last purged){{extract|currentdatetime}}
→ 09:18 24 October 2024
The following confirms that 16 February 2000 in the Julian calendar was 29 February 2000 in the Gregorian calendar.
{{extract|julian|Feb 16, 2000|show=juliandate}}
→ 2451604 (Julian calendar was specified){{extract|juliandate|2451604}}
→ 29 February 2000 (Gregorian calendar by default)
16 February 2000 in the Julian calendar can be converted to the Gregorian calendar in one line:
{{extract|juliandate|{{extract|julian|16 Feb 2000|show=juliandate}}}}
→ 29 February 2000
增加
These time units can be added to a date:
y
yearsm
monthsd
daysh
hoursmin
minutess
seconds
Multiple periods can be given, separated by spaces. There must be no space between a value and the code for the time unit.
A hyphen can be used for a negative value. Periods are added in the order given.
Examples:
{{extract|2004-04-03|add=28d}}
→ 1 May 2004{{extract|2004-04-03|add=3m 28d}}
→ 31 July 2004{{extract|2004-04-03|add=28d 3m}}
→ 1 August 2004 (the order in which units are added changes the result){{extract|2004-04-03|add=-3d}}
→ 31 March 2004{{extract|2004-04-03|add=-912345d}}
→ 5 May 495 BC{{extract|2004-04-03|add=250h}}
→ 10:00 13 April 2004{{extract|2004-04-03|add=-2.5h}}
→ 21:30 2 April 2004{{extract|2004-04-30|add=-2m}}
→ 29 February 2004{{extract|2004-04-03|add=2y 3m 4d}}
→ 7 July 2006{{extract|2004-04-03|add=5.75d}}
→ 18:00 8 April 2004 (years and months are integer only)
修復
By default, the date entered must be valid. If fix=on
is used, units which are too large are "fixed". For example, 26 hours would be regarded as 1 day and 2 hours.
Entering a day as zero is regarded as the previous day (the last day of the previous month). The day before the previous day would be indicated with -1
.
Similarly, entering a month as zero goes back one month, and entering -1
goes back two months.
Examples:
{{extract|2001|5|31|fix=on}}
→ 31 May 2001 (no fix is required){{extract|2001|5|0|fix=on}}
→ 30 April 2001{{extract|2001|5|-1|fix=on}}
→ 29 April 2001{{extract|2001|125|-1000|fix=on}}
→ 3 August 2008{{extract|2001|0|12|fix=on}}
→ 12 December 2000{{extract|2016|3|0|fix=on}}
→ 29 February 2016
The following shows how to get the date for a given year and day-of-year. For example, June 30, 2001 is day 181 in the year 2001, as can be seen by adding 181 days to the date just before January 1, 2001.
{{extract|June 30, 2001|show=dayofyear}}
→ 181 (date to day-of-year){{extract|2001|1|0|fix=on|add=181d|show=mdy}}
→ June 30, 2001 (day-of-year to date)
Partial
If partial=on
is used, the date may consist of a year only, or a year and month only. Addition is not supported for a partial date.
{{extract|2001|5|partial=on}}
→ May 2001{{extract|2016|partial=on|show=isleapyear}}
→ 1
顯示
The following table lists most of the show parameters that can be used. Some of these work properly only with a full date.
Parameter | Description |
---|---|
show=hide |
display nothing; may be useful with sortable=on
|
show=year |
year |
show=month |
month (1 to 12) |
show=day |
day of month (1 to 31) |
show=hour |
hour (0 to 23) |
show=minute |
minute (0 to 59) |
show=second |
second (0 to 59) |
show=dayabbr |
abbreviated name of day of week |
show=dayname |
full name of day of week |
show=dayofweek |
day-of-week (0=Sunday to 6=Saturday) |
show=dayofweekiso |
day-of-week (1=Monday to 7=Sunday) |
show=dayofyear |
day-of-year (1 to 366) |
show=era |
an era code such as BC or BCE |
show=format |
code for the detected format of the input date (dmy, mdy, ymd) |
show=gsd |
Gregorian serial date |
show=juliandate |
Julian day |
show=isleapyear |
1 if the date is in a leap year; 0 otherwise |
show=monthabbr |
abbreviated name of month |
show=monthdays |
number of days in the month of the date |
show=monthname |
full name of month |
show=dmy |
show date as "day month year" (default) |
show=mdy |
show date as "month day, year" |
show=ymd |
show date as "year-month-day" |
Examples:
{{extract|1 Feb 2001}}
→ 1 February 2001{{extract|FEB 1 2001}}
→ 1 February 2001{{extract|2001-2-1}}
→ 1 February 2001{{extract|1 Feb 2001|show=format}}
→ dmy{{extract|FEB 1 2001|show=format}}
→ mdy{{extract|2001-2-1|show=format}}
→ ymd{{extract|1 Feb 2001|show=mdy}}
→ February 1, 2001{{extract|1 Feb 2001|show=ymd}}
→ 2001-02-01{{extract|June 30, 2001|show=dayname}}
→ Saturday{{extract|June 30, 2001|show=dayofyear}}
→ 181{{extract|2001-2-1|show=monthname}}
→ February{{extract|2001-2-1|show=a %{dayname} in %{monthname} }}
→ a Thursday in February
Some show
options will not produce a useful result with a partial date, for example:
{{extract|2001|partial=on|show=juliandate}}
→ juliandate{{extract|2001|partial=on|show=monthname}}
→ monthname
Sortable
The sort options are:
Parameter | Description |
---|---|
sortable=off |
No sort key (default). |
sortable=on |
Output a hidden sort key for use in sortable tables. |
sortable=debug |
Same as sortable=on but the sort key is displayed for testing.
|
The sort key is calculated from the juliandate
value. For a partial date such as May 2016, the first day in the range is used (1 May 2016).
If wanted, show=hide
can be used so the date is not displayed.
Examples:
{{extract|1 Jan 2001|sortable=on}}
→ 1 January 2001{{extract|1 Jan 2001|sortable=on|show=hide}}
→{{extract|2300 BCE|partial=on|sortable=debug}}
→ 7005881367500000000♠2300 BCE{{extract|1 Jan 2001|sortable=debug}}
→ 7006245191050000000♠1 January 2001{{extract|1 Jan 2001|sortable=debug|show=hide}}
→ 7006245191050000000♠{{extract|00:12 1 Jan 2001|sortable=debug|show=hide}}
→ 7006245191050833333♠