var time = 187; var h = time / 60 ^ 0; if (h) { var m = time % 60; if (m < 10) m = '0' + m; time = h + ' ч ' + m + ' м'; } else { time = time + ' м'; } alert(time);