Template:format seconds

From Homestar Runner Wiki

(Difference between revisions)
Jump to: navigation, search
(new template)
(only pad minutes when there are hours)
 
Line 1: Line 1:
-
<includeonly>{{#ifexpr: ({{{1}}}>=3600)|{{#expr: ({{{1}}}-({{{1}}} mod 3600))/3600}}:|}}<!-- /* Calculate the hours and only display more than 0 hours. */
+
<includeonly>{{#ifexpr: ({{{1}}}>=3600)|{{#expr: ({{{1}}}-({{{1}}} mod 3600))/3600}}:<!-- /* Calculate the hours and only display more than 0 hours. */
-
-->{{#ifexpr: ((({{{1}}}-({{{1}}} mod 60))/60) mod 60)<10|0|}}<!-- /* Calculate the minutes and pad with leading zero if less than 10. */
+
-->{{#ifexpr: ((({{{1}}}-({{{1}}} mod 60))/60) mod 60)<10|0|}}|}}<!-- /* Calculate the minutes and pad with leading zero if less than 10. Padding of minutes is only shown when there are hours to display. */
-->{{#expr: (({{{1}}}-({{{1}}} mod 60))/60) mod 60}}:<!-- /* Calculate the minutes. */
-->{{#expr: (({{{1}}}-({{{1}}} mod 60))/60) mod 60}}:<!-- /* Calculate the minutes. */
-->{{#ifexpr: ({{{1}}} mod 60)<10|0|}}<!-- /* Calculate the seconds and pad with leading zero if less than 10. */
-->{{#ifexpr: ({{{1}}} mod 60)<10|0|}}<!-- /* Calculate the seconds and pad with leading zero if less than 10. */

Current revision as of 03:05, 2 January 2025

This template converts a value of seconds into "hh:mm:ss" format ("hours:minutes:seconds"). Hours are only displayed if the total meets or exceeds 1 hour.

Usage:

{{ format seconds | seconds }}

where seconds is the value of seconds to format. This parameter is required.

Examples:

{{format seconds|121}}
  • Yields: 2:01
{{format seconds|119}}
  • Yields: 1:59
{{format seconds|3601}}
  • Yields: 1:00:01
{{format seconds|3599}}
  • Yields: 59:59
{{format seconds|7199}}
  • Yields: 1:59:59
{{format seconds|90001}}
  • Yields: 25:00:01

[edit] See Also

Personal tools