mercredi 24 décembre 2014

Get time left from now with giving time of tomorrow in 24 format in javascript


Happy new year everyone,,


I'm using this function to get the time left between today and giving date (Hours:Minutes) and it works fine...



function PrayerTimeLeft(prayerTime){
var today = new Date();
var prayerTimeDate = new Date();
prayerTimeDate.setHours(prayerTime.substring(0,2));
prayerTimeDate.setMinutes(prayerTime.substring(3,5));
var diffMs = (prayerTimeDate - today);
var diffHrs = Math.round((diffMs % 86400000) / 3600000);
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000);
return {
getDiffMin:function(){
return diffMins;
},
getDiffHrs:function(){
return diffHrs;
}
};
}


I can use it like this:



var test = new PrayerTimeLeft("14:00"); // and today was 12:00 in 24 format
console.log(test.getDiffHrs()); //It will show 2 hours


I'm here trying to get how many left for a coming Prayer time, there are five Prayers: First: 5:00 Second: 11:42 Third: 14:26 Fourth: 16:50 Fifth: 18:07


My problem is if the current time (let's say it will 23:00) is between fifth and first one, here we are talking about tomorrow time which is between (5:00 & 18:07)


I can't realize this reverse things?





Aucun commentaire:

Enregistrer un commentaire