I am trying to add time to a Date object in javascript, but not getting the expected results. I am trying to pull out a timer on a page and add it to the current time to get the unix timestamp value when the timer reaches zero. The time on the page is displayed as "HH: MM: SS". This is what I have:
time=getTimerText.split(":");
seconds=(time[0]*3600+time[1]*60+time[2])*1000;
to convert time to milliseconds.
fDate=new Date();
fDate.setTime(fDate.getTime()+seconds);
add milliseconds to javascript timestamp
alert(Math.round(fDate.getTime() / 1000));
convert javascript timestamp to unix timestamp
Since the timer is counting down, I have to get the same result every time I run the script, but I do not. Can anyone see what I can do wrong here?
source
share