javascript - How can I format minutes into hour and minutes but only show hour if it's > 60 minutes? -
i have function converts minutes hour / minute format:
return math.floor(diffmins / 60) + " hour " + diffmins % 60 + " minutes.";
what make if there no hours "0 hours" not show. can recommend way can this?
floor; check if more 0 hours; if not, output empty string; otherwise check if 1 hour, if yes, output "1 hour", if not, output number of hours + "hours"
var h = math.floor(diffmins / 60); var hours = (h > 0 ? (h==1 ? "1 hour" : h+" hours") : ""); var mins = diffmins % 60; return hours + mins > 1 ? mins + " minutes." : " 1 minute." ;
Comments
Post a Comment