I am making a website where if a user logs in, the user is given a certain logout time, where the logout time is defined and the timeleft is obtained from the logout time - server time.
I've already got the logout time and server time via PHP, but I want to display the time left dynamically thus requiring Javascript. I've tried using the following code:
function timerStart(arg1, arg2){
var counter = setInterval(function() {getTimeLeft(arg1,arg2); }, 1000);
}
function getTimeLeft(arg_endtime, arg_currenttime){
var endtime = new Date(arg_endtime);
var curtime = new Date(arg_currenttime);
var timeleft = new Date(endtime - curtime); //endtime - curtime;
tlHours = timeleft.getHours();
tlMinutes = timeleft.getMinutes();
tlSeconds = timeleft.getSeconds();
document.getElementById("timeleft").value = tlHours + ":" + tlMinutes + ":" + tlSeconds;
}
Where arg1's value is '2011:10:11 17.30.00' and arg2's value is '2011:10:11 15:55:31' as a string (yes, they are in different format). But when I tried the above codes I get NaN:NaN:NaN. I am very new to Javascript (3 days) and trying to catch up a deadline so a thorough explanation is very appreciated.