IMG-LOGO

Convert minutes to a string of hours and minutes in Javascript

andy - 05 Sep, 2014 8060 Views 0 Comment

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.

Related Articles