nul toevoegen in counter
Omdat het vandaag nog maar 98 dagen is, wil ik graag een "0" vooraan toevoegen, zodat er 098 dagen komt te staan.
Waar zet ik de extra nul in de code?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var current=""; //--> eindtijd bereikt
var year=2013;
var month=1;
var day=1;
var hour=0;
var minute=0;
var tz=+1; // GMT
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countdown(yr,m,d,hr,min){
theyear=yr;themonth=m;theday=d;thehour=hr;theminute=min;
var today=new Date();
var todayy=today.getYear();
if (todayy < 1000) {todayy+=1900;}
var todaym=today.getMonth();
var todayd=today.getDate();
var todayh=today.getHours();
var todaymin=today.getMinutes();
var todaysec=today.getSeconds();
var todaystring1=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
var todaystring=Date.parse(todaystring1)+(tz*1000*60*60);
var futurestring1=(montharray[m-1]+" "+d+", "+yr+" "+hr+":"+min);
var futurestring=Date.parse(futurestring1)-(today.getTimezoneOffset()*(1000*60));
var dd=futurestring-todaystring;
var dday=Math.floor(dd/(60*60*1000*24)*1);
var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
document.getElementById('count0').innerHTML=current;
document.getElementById('dday').style.display="none";
return;
}
else {
document.getElementById('count0').style.display="none";
document.getElementById('dday').innerHTML=dday;
setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000);
}
}
var year=2013;
var month=1;
var day=1;
var hour=0;
var minute=0;
var tz=+1; // GMT
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countdown(yr,m,d,hr,min){
theyear=yr;themonth=m;theday=d;thehour=hr;theminute=min;
var today=new Date();
var todayy=today.getYear();
if (todayy < 1000) {todayy+=1900;}
var todaym=today.getMonth();
var todayd=today.getDate();
var todayh=today.getHours();
var todaymin=today.getMinutes();
var todaysec=today.getSeconds();
var todaystring1=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
var todaystring=Date.parse(todaystring1)+(tz*1000*60*60);
var futurestring1=(montharray[m-1]+" "+d+", "+yr+" "+hr+":"+min);
var futurestring=Date.parse(futurestring1)-(today.getTimezoneOffset()*(1000*60));
var dd=futurestring-todaystring;
var dday=Math.floor(dd/(60*60*1000*24)*1);
var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
document.getElementById('count0').innerHTML=current;
document.getElementById('dday').style.display="none";
return;
}
else {
document.getElementById('count0').style.display="none";
document.getElementById('dday').innerHTML=dday;
setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000);
}
}
document.getElementById('dday').innerHTML=dday;
veranderen in
document.getElementById('dday').innerHTML= '0' + dday;
Toevoeging op 24/09/2012 10:19:03:
Of het kan op regel 26
var dday=Math.floor(dd/(60*60*1000*24)*1);
veranderen in
var dday= '0' + Math.floor(dd/(60*60*1000*24)*1);
Gewijzigd op 24/09/2012 10:19:14 door Marvin H