Tuesday, 19 December 2017

Get Remaining Hours In Day at Gap JavaScript

Get Remaining Hours In Day at Gap JavaScript

I am sharing my JavaScript code to get remaining hours at the gap of specific minutes. May be this code will helpful for someone.

var t = 0;
var h = 0;
var m = 0;

var totalHoursRemaining = [];
var hrs = [];
String.prototype.paddingLeft = function (paddingValue) {
    return String(paddingValue + this).slice(-paddingValue.length);
};
var date = new Date();
var ch = date.getHours();
ch = ch % 12;
ch = ch ? ch : 12; // the hour '0' should be '12'
var cm = date.getMinutes();

for (h = ch; h < 12; h++{
    for (m = 0; m < 60; m++{
        if (m % 5 == 0{
            var timstr = h + ":" + m.toString().paddingLeft("00");
            //if(m > cm) {   
            totalHoursRemaining.push(timstr);
            //}
        }
    }
}

var totalTimeLost = [];
for (var nm = 0; nm < cm; nm++{
    if (nm % 5 == 0{
        var timstr = ch + ":" + nm.toString().paddingLeft("00");
        totalTimeLost.push(timstr);
    }
}

function remove(array, element) {
    const index = array.indexOf(element);
    array.splice(index, 1);
}

for (s = 0; s < totalHoursRemaining.length; s++{
    for (s1 = 0; s1 < totalTimeLost.length; s1++{
        if (totalHoursRemaining[s== totalTimeLost[s1]) {
            remove(totalHoursRemaining, totalTimeLost[s1]);
        }
    }
}

console.log(totalTimeLost);

console.log(totalHoursRemaining);

No comments:

Post a Comment

Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...