There are a couple parts to this question. I am not opposed to using a jQuery plugin if anyone knows of one that will accomplish what I want done.
Q1 - How d
The function below will take as input # of minutes and output time in the following format: Hours:minutes. I used Math.trunc(), which is a new method added in 2015. It returns the integral part of a number by removing any fractional digits.
function display(a){
var hours = Math.trunc(a/60);
var minutes = a % 60;
console.log(hours +":"+ minutes);
}
display(120); //"2:0"
display(60); //"1:0:
display(100); //"1:40"
display(126); //"2:6"
display(45); //"0:45"
var timeConvert = function(n){
var minutes = n%60
var hours = (n - minutes) / 60
console.log(hours + ":" + minutes)
}
timeConvert(65)
this will log 1:5 to the console. It is a short and simple solution that should be easy to understand and no jquery plugin is necessary...
Alternated to support older browsers.
function minutesToHHMM (mins, twentyFour) {
var h = Math.floor(mins / 60);
var m = mins % 60;
m = m < 10 ? '0' + m : m;
if (twentyFour === 'EU') {
h = h < 10 ? '0' + h : h;
return h+':'+m;
} else {
var a = 'am';
if (h >= 12) a = 'pm';
if (h > 12) h = h - 12;
return h+':'+m+a;
}
}