跳转到内容

模板:Countdown:修订间差异

来自osm&bio
Magezeya留言 | 贡献
无编辑摘要
Magezeya留言 | 贡献
无编辑摘要
第1行: 第1行:
<includeonly>
<includeonly>
<!-- 简化倒计时模板 -->
{{#if: {{{1|}}}
{{#if: {{{1|}}}
   | {{#time: U | {{{1}}} }}
   | {{#if: {{{utc|}}}
     {{#ifexpr: {{#time: U | {{{1}}} }} > {{#time: U}}
     | {{#if: {{{time|}}}
      | <!-- 未来日期 - 倒计时 -->
      | {{#time: U | {{{1}}} {{{utc}}} }}
        距离{{{1}}}还有 <strong>{{#expr: floor(({{#time: U | {{{1}}} }} - {{#time: U}}) / 86400) }}</strong> 天
      | {{#time: U | {{{1}}} 00:00:00 {{{utc}}} }}
      | <!-- 过去日期 - 正计时 -->
        {{{1}}}已过去 <strong>{{#expr: floor(({{#time: U}} - {{#time: U | {{{1}}} }}) / 86400) }}</strong> 天
     }}
     }}
    | {{#if: {{{time|}}}
      | {{#time: U | {{{1}}} }}
      | {{#time: U | {{{1}}} 00:00:00 }}
    }}
  }}
  {{#switch: {{{time|day}}}
    | day = {{#expr: floor(({{#time: U}} - ({{#if: {{{utc|}}}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} {{{utc}}} }}
          | {{#time: U | {{{1}}} 00:00:00 {{{utc}}} }}
        }}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} }}
          | {{#time: U | {{{1}}} 00:00:00 }}
        }}
      }})) / 86400) }}
    | hour = {{#expr: floor(({{#time: U}} - ({{#if: {{{utc|}}}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} {{{utc}}} }}
          | {{#time: U | {{{1}}} 00:00:00 {{{utc}}} }}
        }}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} }}
          | {{#time: U | {{{1}}} 00:00:00 }}
        }}
      }})) / 3600) }}
    | minute = {{#expr: floor(({{#time: U}} - ({{#if: {{{utc|}}}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} {{{utc}}} }}
          | {{#time: U | {{{1}}} 00:00:00 {{{utc}}} }}
        }}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} }}
          | {{#time: U | {{{1}}} 00:00:00 }}
        }}
      }})) / 60) }}
    | second = {{#expr: {{#time: U}} - ({{#if: {{{utc|}}}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} {{{utc}}} }}
          | {{#time: U | {{{1}}} 00:00:00 {{{utc}}} }}
        }}
        | {{#if: {{{time|}}}
          | {{#time: U | {{{1}}} }}
          | {{#time: U | {{{1}}} 00:00:00 }}
        }}
      }}) }}
  }}
   | 错误:未提供日期参数
   | 错误:未提供日期参数
}}
}}
第14行: 第58行:


<noinclude>
<noinclude>
== 倒计时/正计时模板 ==
== 倒计时模板 ==
用于显示距离某个日期的倒计时或已过去的时间。
计算指定日期与当前时间的时间差,只输出数字结果。


=== 使用方法 ===
=== 使用方法 ===
<pre>
<pre>
{{Countdown|目标日期}}
{{Countdown|目标日期|utc=时区|time=精度}}
</pre>
</pre>
=== 参数 ===
; 1
: 目标日期 (YYYY-MM-DD格式)
; utc
: 时区偏移 (可选,例如+8表示UTC+8)
; time
: 精度 (可选,day-天/hour-小时/minute-分钟/second-秒,默认为day)


=== 示例 ===
=== 示例 ===
<pre>
<pre>
{{Countdown|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}} → 包含时间的分钟差
</pre>
[[Category:时间模板]]
</noinclude>
{{Countdown|2023-12-31}}  // 显示距离2023年12月31日还有/已过多少天
{{Countdown|2023-12-31}}  // 显示距离2023年12月31日还有/已过多少天
{{Countdown|2023-06-15}}  // 显示距离2023年6月15日还有/已过多少天
{{Countdown|2023-06-15}}  // 显示距离2023年6月15日还有/已过多少天

2025年8月21日 (四) 14:27的版本


倒计时模板

计算指定日期与当前时间的时间差,只输出数字结果。

使用方法

{{Countdown|目标日期|utc=时区|time=精度}}

参数

1
目标日期 (YYYY-MM-DD格式)
utc
时区偏移 (可选,例如+8表示UTC+8)
time
精度 (可选,day-天/hour-小时/minute-分钟/second-秒,默认为day)

示例

{{Countdown|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}} → 包含时间的分钟差


1703980800

 766


检测到模板循环:模板:Countdown // 显示距离2023年12月31日还有/已过多少天 检测到模板循环:模板:Countdown // 显示距离2023年6月15日还有/已过多少天

</noinclude> // 显示距离2023年12月31日还有/已过多少天

1686787200

 965


检测到模板循环:模板:Countdown // 显示距离2023年12月31日还有/已过多少天 检测到模板循环:模板:Countdown // 显示距离2023年6月15日还有/已过多少天

</noinclude> // 显示距离2023年6月15日还有/已过多少天