JavaScript/Timer

These JavaScript functions format a given number of seconds as an hour-minute-second or minute-second time or only show hours when one hour is exceeded. The names of the functions are  and   and   respectively. The name of the third refers to the common use of this timer layout in multimedia player software.

Each of these functions is bundled with a separate function ( suffix) to be able to handle negative and invalid inputs. Should a negative number be entered, the time is returned with a prepended dash, and if no valid number is entered, " " is returned. The thin spaces between the dashes are necessary to match the width of the digits.

The timer functions can be seen in action by running the media timer script on a web page with a video or an audio element.