I am developing a typing application using PHP and MySQL and little bit of javascript. The PHP code is used to get the server time. I am using the following javascript function to display the start time and end time(by adding 5 min with the minute value of start time) in the browser.
function display(){
// get the server time using PHP and print the start time and end time
var servDateArray='<?php print date("Y/n/d/H/i/s", time())?>'.split('/');
starttime_year = servDateArray[0];
starttime_month = servDateArray[1];
starttime_day = servDateArray[2];
starttime_hour = servDateArray[3];
starttime_minutes = servDateArray[4];
starttime_seconds = servDateArray[5];
// print the Start time
document.getElementById("starttime_echoed").innerHTML= starttime_hour+":"+starttime_minutes+":"+starttime_seconds;
document.typing.starttime.value=starttime_hour+":"+starttime_minutes+":"+starttime_seconds;
// print the End time
endtime_hour = parseInt(starttime_hour) + 0;
endtime_min = parseInt(starttime_minutes) + 5;
endtime_sec = parseInt(starttime_seconds) + 0;
if (endtime_sec>=60) { endtime_sec = -(60 - endtime_sec); endtime_min = parseInt(endtime_min)+1; }
if (endtime_min>=60) { endtime_min = -(60 - endtime_min); endtime_hour = parseInt(endtime_hour)+1; }
if (endtime_hour>=24) { endtime_hour = -(24 - endtime_hour); }
if (endtime_sec<=9) { endtime_sec="0"+endtime_sec; }
if (endtime_min<=9) { endtime_min="0"+endtime_min; }
if (endtime_hour<=9) { endtime_hour="0"+endtime_hour; }
document.getElementById("endtime_echoed").innerHTML= endtime_hour+":"+endtime_min+":"+endtime_sec;
document.typing.endtime.value=endtime_hour+":"+endtime_min+":"+endtime_sec;
displayTimer();
}
The above code works perfectly well for all input values of Hours, minutes and seconds excepts when hour, minute and second are set to either 8 or 9. However, I have tried to debug by inserting a line of code alert(parseInt(starttime_minutes)); after the line endtime_min = parseInt(starttime_minutes) + 5; and it returned 0 when I supplied 8 or 9 as value for minute. I am sure this function returns 0 for hours, minutes and seconds. To be very specific I am giving you am example: If the server time is say 08:09:37 then the end time becomes 00:05:37. I am getting perplexed. Please help.