I'm currently working on a project in JavaScript that tell the user the amount of time left in a class period based on the users time. I am able to determine the time using the following code.
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt').innerHTML =
h + ":" + m + ":" + s;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
My goal is to subtract the current time based on the user by the amount of time left in the period. Here are the period times I want to use.
Period 1 7:45 - 8:34
Period 2 8:38 - 9:30
Period 3 9:34 - 10:23
Period 4 10:27 - 11:16
Period 5 11:20 - 12:38
Period 6 12:42 - 1:31
Period 7 1:35 - 2:25
So if its 8:30 it will return to the user "There is 4 minute(s) left in period 1" In this scenario the number 4 will be represented by a variable and same applies for "1" based on the period.