模板:Countdown:修订间差异
外观
无编辑摘要 |
无编辑摘要 |
||
| (未显示同一用户的5个中间版本) | |||
| 第1行: | 第1行: | ||
<includeonly> | <includeonly>{{#if: {{{1|}}} | ||
{{#if: {{{1|}}} | |{{#if: {{{utc|}}} | ||
| {{#if: {{{utc|}}} | |{{#if: {{#pos:{{{1}}}|:}} | ||
| {{#if: {{#pos:{{{1}}}|:}} | |{{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} {{{utc}}} }}) / {{#switch: {{{time|day}}}|day=86400|hour=3600|minute=60|second=1|#default=86400}} )}}{{{text|}}} | ||
| {{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} {{{utc}}} }}) / | |{{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} 00:00:00 {{{utc}}} }}) / {{#switch: {{{time|day}}}|day=86400|hour=3600|minute=60|second=1|#default=86400}} )}}{{{text|}}} | ||
| {{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} 00:00:00 {{{utc}}} }}) / | |||
}} | }} | ||
| {{#if: {{#pos:{{{1}}}|:}} | |{{#if: {{#pos:{{{1}}}|:}} | ||
| {{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} }}) / | |{{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} }}) / {{#switch: {{{time|day}}}|day=86400|hour=3600|minute=60|second=1|#default=86400}} )}}{{{text|}}} | ||
|{{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} 00:00:00 }}) / {{#switch: {{{time|day}}}|day=86400|hour=3600|minute=60|second=1|#default=86400}} )}}{{{text|}}} | |||
| {{#expr: floor( ({{#time: U}} - {{#time: U | {{{1}}} 00:00:00 }}) / | |||
}} | }} | ||
}} | }} | ||
| 错误:未提供日期参数 | |错误:未提供日期参数 | ||
}} | }}</includeonly> | ||
</includeonly> | |||
<noinclude> | <noinclude> | ||
== | |||
== 模板描述 == | |||
'''Countdown''' - 计算指定日期与当前时间的时间差,可自定义输出格式。 | |||
=== 使用方法 === | === 使用方法 === | ||
<pre> | <pre> | ||
{{Countdown|目标日期|utc=时区|time=精度}} | {{Countdown|目标日期|utc=时区|time=精度|text=后缀文本}} | ||
</pre> | </pre> | ||
=== | === 参数说明 === | ||
; 1 | ; 1 (必需) | ||
: | : 目标日期,格式为YYYY-MM-DD或YYYY-MM-DD HH:MM:SS | ||
; utc | ; utc (可选) | ||
: | : 时区偏移,例如+8表示UTC+8,-5表示UTC-5 | ||
; time | ; time (可选) | ||
: | : 时间精度,可选值:day(天)、hour(小时)、minute(分钟)、second(秒),默认为day | ||
; text (可选) | |||
: 显示在数字后面的后缀文本 | |||
=== 示例 === | === 示例 === | ||
<pre> | <pre> | ||
{{Countdown|2023-12-31}} → | {{Countdown|2023-12-31}} → 输出距离2023年12月31日的天数 | ||
{{Countdown|2023-12-31|utc=+8}} → 使用UTC+ | {{Countdown|2023-12-31|utc=+8}} → 使用UTC+8时区计算天数 | ||
{{Countdown|2023-12-31|time=hour}} → 输出小时差 | {{Countdown|2023-12-31|time=hour}} → 输出小时差 | ||
{{Countdown|2023-12-31 12:30:45|time=minute}} → | {{Countdown|2023-12-31 12:30:45|time=minute}} → 输出分钟差 | ||
{{Countdown|2025-8-21|text=天了}} → 输出"X天了" | |||
</pre> | </pre> | ||
=== 典型应用场景 === | |||
* 显示距离某个重要日期的倒计时 | |||
* 计算文章/页面的存在时间 | |||
* 显示活动剩余时间 | |||
* 记录项目持续时间 | |||
=== 注意事项 === | |||
* 日期格式必须正确,否则会报错 | |||
* 时区参数需符合±HH格式 | |||
* 结果为整数,向下取整 | |||
[[Category:时间模板]] | [[Category:时间模板]] | ||
</noinclude> | </noinclude> | ||
2025年8月21日 (四) 15:17的最新版本
模板描述
Countdown - 计算指定日期与当前时间的时间差,可自定义输出格式。
使用方法
{{Countdown|目标日期|utc=时区|time=精度|text=后缀文本}}
参数说明
- 1 (必需)
- 目标日期,格式为YYYY-MM-DD或YYYY-MM-DD HH:MM:SS
- utc (可选)
- 时区偏移,例如+8表示UTC+8,-5表示UTC-5
- time (可选)
- 时间精度,可选值:day(天)、hour(小时)、minute(分钟)、second(秒),默认为day
- text (可选)
- 显示在数字后面的后缀文本
示例
{{Countdown|2023-12-31}} → 输出距离2023年12月31日的天数
{{Countdown|2023-12-31|utc=+8}} → 使用UTC+8时区计算天数
{{Countdown|2023-12-31|time=hour}} → 输出小时差
{{Countdown|2023-12-31 12:30:45|time=minute}} → 输出分钟差
{{Countdown|2025-8-21|text=天了}} → 输出"X天了"
典型应用场景
- 显示距离某个重要日期的倒计时
- 计算文章/页面的存在时间
- 显示活动剩余时间
- 记录项目持续时间
注意事项
- 日期格式必须正确,否则会报错
- 时区参数需符合±HH格式
- 结果为整数,向下取整