Published on: 05 September, 2014

Convert minutes to a string of hours and minutes in Javascript

Posted by andy | 2128 views 1 likes 0 favourites 0 comments
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.
Share your article with us and add your own google adsense account to earn extra money. Plus, you can promote a link back to your site.
Related Articles
Published on: 20 June, 2016
Google Analytics is one of the best free analytics site tracker. It gives you an idea the statistic of your visitors like the country they come from, the URL or keyword they search to go to your site or even the demographic or ages of your visitors. If you are a developer, you definitely do not want to track any data when you are in development phase. In this tutorial, you will learn how to disable google analytics for local development by using a javascript code if condition.
Published on: 13 May, 2016
To convert a number value into money format in Javascript can be done easily using Javascript. Firstly you will need to use the built in toFixed function that will return a number value into two decimal point and then using a regular expression to reformat the value.
Related Tutorials