vendredi 29 mars 2019

Get _m_s time format from milliseconds

I could have any value in milliseconds like :

1040370

I must alert converted time format : _m_s [ie:17m20s]

Here is how I do it :

function ms(a){
var m = a / 1000 / 60,
s = Math.round(('0.' + m.toString().split('.')[1]) * 60);
m = m.toString().split('.')[0];
alert(m + 'm' + s + 's');
}

ms(1040370);

Is it satisfactory or is there a better way to accomplish the same ?

Aucun commentaire:

Enregistrer un commentaire