Reputation: 1125
I am having trouble adding in a year to my count up code.
I have tried this:
days=Math.floor(difference/(60*60*1000*24)*1);
days=Math.floor(difference/(60*60*1000*24)*1/365);
hours=Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1/365);
mins=Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1/365);
secs=Math.floor((((difference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1/365);
document.getElementById('countup').setAttribute("uptime",years+':'days+':'+hours+':'+mins+':'+secs)
document.getElementById('years').firstChild.nodeValue = years;
document.getElementById('days').firstChild.nodeValue = days;
document.getElementById('hours').firstChild.nodeValue = hours;
document.getElementById('minutes').firstChild.nodeValue = mins;
document.getElementById('seconds').firstChild.nodeValue = secs;
But it still didn't work. Also how would I allow for a leap year?
Working fiddle without year below:
https://jsfiddle.net/ma9ic/3jxm4e7t/
Can someone point me in the right direction. Is there an easier method for creating the same effect with jQuery?
Upvotes: 2
Views: 119
Reputation: 4122
I think you're going to have a rough time trying to create this in plain JS and jQuery isn't really an appropriate option as it's primarily a DOM manipulation library.
It's a library dedicated to this sort of thing and handles things which you probably weren't even thinking about (like Timezones).
Just browse through the code and see what I mean.
Upvotes: 1