Skip to content

Instantly share code, notes, and snippets.

@Spittal
Created July 31, 2014 22:27

Revisions

  1. Spittal renamed this gist Jul 31, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Spittal revised this gist Jul 31, 2014. No changes.
  3. Spittal created this gist Jul 31, 2014.
    24 changes: 24 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    .filter('formatTime', function() {
    return function(milliseconds,withHour) {
    var seconds = parseInt((milliseconds/1000)%60);
    var minutes = parseInt((milliseconds/(1000*60))%60);
    var hours = parseInt((milliseconds/(1000*60*60))%24);
    var out = "";

    minutes = (parseInt(minutes) + (60 * parseInt(hours)));
    minutes = (minutes < 10) ? "0" + minutes : minutes;
    seconds = (seconds < 10) ? "0" + seconds : seconds;

    out = minutes + ":" + seconds;

    if(withHour) {
    hours = (hours < 10) ? "0" + hours : hours;
    minutes = (minutes < 10) ? "0" + minutes : minutes;
    seconds = (seconds < 10) ? "0" + seconds : seconds;

    out = hours + ":" + minutes + ":" + seconds;
    }

    return out;
    };
    });