nevím si s tím rady a tady tomu jistě někdo rozumí..
(pokoušel jsem se to upravit ale prostě na to nemám)
chtěl bych aby to správně skloňovalo tzn.:
dny (1 den, 2 dny, 3 dny, 4 dny, 5 dnů, 6 dnů atd...)
u týdnů měsíců a roků taktéž.
Zároveň se script chová tak že když je výsledný čas delší než dva roky tak už to počítá jen na roky..
Chtěl bych aby to ukazovalo aktuální čas až po úroveň dnů např.: 2 roky 4 měsíce 3 týdny 6 dnů
Předem děkuji za reakce...
Zdrojový soubor je zde :
Kód: Vybrat vše
<HTML>
<head>
<script type="text/javascript">
<!--
function getAge(birth)
{
var now = new Date();
aSecond = 1000;
aMinute = aSecond * 60;
aHour = aMinute * 60;
aDay = aHour * 24;
aWeek = aDay * 7;
aMonth = aDay * 30;
var age = now.getTime() - birth.getTime();
if (age < 0) {
return "not born yet"
}
years = (new Date(now.getTime() - aMonth* (birth.getMonth()) )).getFullYear()
- (new Date(birth.getTime() - aMonth* (birth.getMonth()) )).getFullYear();
offsetNow = (new Date(now.getTime() - aDay* (birth.getDate() -1) ));
offsetBirth = (new Date(birth.getTime() - aDay* (birth.getDate() -1) ));
if(years > 1){
months = years*12 + ( offsetNow.getMonth() - offsetBirth.getMonth()) ;
}else{
months = (now.getFullYear() - birth.getFullYear())*12 + ( offsetNow.getMonth() - offsetBirth.getMonth()) ;
}
agestr="";
if (months < 24){
weeks = Math.floor(age / aWeek);
age -= weeks * aWeek;
days = Math.floor(age / aDay);
if(weeks > 0){
if(weeks == 1){
agestr = agestr + weeks + " týden ";
}else if(weeks < 5){
agestr = agestr + weeks + " týdny ";
}else if(weeks <9){
agestr = agestr + weeks + " týdnů ";
}else{
agestr = agestr + months ;
if(now.getDate() - birth.getDate() > 10){
agestr = agestr + " ½ ";
}
agestr = agestr + " měsíců ";
}
}
if(days > 0){
if(weeks < 9){
if(weeks > 0){
agestr = agestr + " a ";
}
if(days == 1){
agestr = agestr + days + " den ";
}else{
agestr = agestr + days + " dnů ";
}
}
}
}else{
agestr = agestr + years;
if (months%12 > 5 && years<14){
agestr = agestr + " ½ ";
}
agestr = agestr + " let ";
}
return agestr;
}
// -->
</script>
</head>
<BODY>
<BR>
<BR>
<BR>
<CENTER>
<BR>
<script type="text/javascript">
document.write("<font size=2> právě uběhlo " + getAge(new Date("april 11, 2002 ")) + "</font>");
</script>
</CENTER>
</body>
</html>

