Created
July 31, 2014 22:27
-
-
Save Spittal/549fb0e3dbc06f6c0c74 to your computer and use it in GitHub Desktop.
Angular Time Filter that takes milliseconds and returns it as full minutes and seconds. For example: 60000 = 1:00, 6000000 = 100:00, 6000000 = 1:40:00 (withHour = true)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your code is adding an extra "0" to the time withHour, please move the first step to a else after the if
.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 = "";
});