Published on: 05 September, 2014

Convert minutes to a string of hours and minutes in Javascript

Tumblr Digg Google Plus

You can use the following javascript code snippet to convert minutes to a string contains hours and minutes conversion.

function getHour(value) {
    if (value == null) { return ""; }
    if (value <= 0) { return ""; }
    var hours = Math.floor(value / 60);
    var minutes = value % 60;
    var hour = (hours > 1) ? hours + " hrs " : hours + " hr ";
    var min = (minutes > 0) ? minutes + " mins" : "";
    return hour + min;
}

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.