How would I bring together my checkTime and checkMinute function into one so that when I do an offset of (m + 30) it will also make h go to the next hour when m reaches 60. Thanks!
Currently My code tells the time and can take on offset for hours on a 24 hour scale, my issue is it does not allow me to change the code in offset of + 30 minutes which I would like the ability to do.
My if statements aren't getting me the outcome I want which is when minutes hit 60 from doing an offset of + 30 then the hour will go to the next one instead of only affecting the minutes.
I believe I would need to bring the two function together but am not sure how to do this accurately.
function addLeadingZero(n) {
return n < 10 ? '0' + n : n;
}
function timeClock(timeZoneOffset) {
var d = new Date();
d.setHours(d.getUTCHours() + timeZoneOffset); // set time zone offset
var h = d.getUTCHours();
var m = d.getUTCMinutes();
var s = d.getUTCSeconds();
/* h = h % 12;
h = h ? h : 12; // replace '0' w/ '12' */
/* h = checkHour(h) */
m = checkTime(m);
s = checkTime(s);
h = addLeadingZero(h);
document.all["txt3"].innerHTML = /*+ checkHour*/ (h - 4) + ':' + m + ':' + s + ' ';
document.all["txt1"].innerHTML = /*+ checkHour*/ (h + 3) + ':' + m + '' + ' ';
document.all["txt2"].innerHTML = h + ':' + checkMinute(m + 30) + '' + ' ';
document.all["txt4"].innerHTML = h + ':' + m + '' + ' ';
document.all["txt5"].innerHTML = h + ':' + m + '' + ' ';
setTimeout(function() {
timeClock(timeZoneOffset)
}, 500);
}
function checkTime(i) {
var j = i;
if (i < 10) {
j = "0" + i;
}
return j;
}
function checkHour(i) {
var j = i;
if (i > 23) {
j = j - 24;
}
if (i < 0) {
j = "0" + i;
}
return j;
}
function checkMinute(i) {
var j = i;
if (i > 59) {
j = j - 60;
}
if (i < 0) {
j = "0" + i;
}
return j;
}
/* setInterval(function() {
startTime();
}, 500);
})(jQuery); */
window.onload = function() {
timeClock(2);
}
<div id="txt3"></div>
<div id="txt1"></div>
<div id="txt2"></div>
<div id="txt4"></div>
<div id="txt5"></div>