Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Duration: Difference between revisions

Template page
Tyraeis (talk | contribs)
Add duration template for converting durations in seconds to a more human-readable format
 
Tyraeis (talk | contribs)
Hide minutes/seconds if they are zero
Line 1: Line 1:
<includeonly>
<includeonly>
{{#if: {{{seconds}}} | {{#ifexpr: {{{seconds}}} > 3600 | {{#expr: trunc ({{{seconds}}} / 3600)}}&nbsp;h&nbsp;}}{{#ifexpr: {{{seconds}}} > 60 | {{#expr: trunc (({{{seconds}}}-(trunc ({{{seconds}}} / 3600))*3600) / 60)}}&nbsp;min&nbsp;}}{{#expr: {{{seconds}}}-(trunc ({{{seconds}}} / 60))*60 }}&nbsp;s}}
{{#if: {{{seconds}}} | {{#ifexpr: {{{seconds}}} > 3600 | {{#expr: trunc ({{{seconds}}} / 3600)}}&nbsp;h&nbsp;}}{{#ifexpr: {{{seconds}}} mod 3600 > 60 | {{#expr: trunc (({{{seconds}}}-(trunc ({{{seconds}}} / 3600))*3600) / 60)}}&nbsp;min&nbsp;}}{{#ifexpr: {{{seconds}}} mod 60 > 0 or {{{seconds}}} = 0 | {{#expr: {{{seconds}}}-(trunc ({{{seconds}}} / 60))*60 }}&nbsp;s}}}}
</includeonly>
</includeonly>
<noinclude>{{Documentation}}</noinclude>
<noinclude>{{Documentation}}</noinclude>

Revision as of 02:31, 19 March 2026

Template documentation[view] [edit] [history] [purge]

This template converts a duration in seconds to a human-readable format that is broken up into hours, minutes, and seconds.

Usage

Use the Seconds, Minutes, Hours and Days parameters to set the duration.

Examples

Wikitext Renders as
{{Duration|seconds=4830}}

1 h 20 min 30 s


{{Duration|hours=2.5}}

Expression error: Unrecognized punctuation character "{".Expression error: Unrecognized punctuation character "{".Expression error: Unrecognized punctuation character "{".


{{Duration|seconds=7200}}

2 h 


{{Duration|hours=2|seconds=30}}

30 s


{{Duration|seconds=333}}

5 min 33 s


{{Duration|seconds=120}}

2 min 


{{Duration|seconds=42}}

42 s