Foster Foster - 5 months ago 22
AngularJS Question

Convert milliseconds to HH:MM:SS

I have been looking through this code but cant really find any

tried to use angular filtering {{bla.bla | date:'HH:mm:ss'}}

but it doesnt work.
can anybody help me please? thanks!

Answer
filter('songTime',function(){

    return function (s) {
        var ms = s % 1000;
        s = (s - ms) / 1000;
        var secs = s % 60;
        s = (s - secs) / 60;
        var mins = s % 60;
        var hrs = (s - mins) / 60;

        return hrs + ':' + mins + ':' + secs + ':' + ms;        
    };
}

and use it like {{bla.bla | songTime }} . You can beautify the date inside the filter.

Comments