详细年龄 生日倒计时

news/2024/7/4 3:58:43 标签: javascript, date, button, function, 脚本
 

脚本说明:
把如下代码加入<body>区域中:
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function run() {
with (document.agecalc) {
dd = parseInt(day.selectedIndex) + 1;
mm = parseInt(month.selectedIndex) + 1;
yy = year.value;
if (yy.length != 4 || isNaN(yy)) {
document.agecalc.timealive.value = "Please enter a 4-digit year.";
document.agecalc.year.select();
document.agecalc.year.focus();
return;
   }
}
days = new Date();
gdate = days.getDate();
gmonth = days.getMonth();
gyear = days.getYear();
if (gyear < 2000) gyear += 1900;
age = gyear - yy;
if ((mm == (gmonth + 1)) && (dd <= parseInt(gdate))) {
age = age;
} else {
if (mm <= (gmonth)) {
age = age;
} else {
age = age - 1;
   }
}
if (age == 0)
age = age;
document.agecalc.timealive.value = "You are " + age+ " years old . . .\n\n";
if (mm <= (gmonth + 1))
age = age - 1;
if ((mm == (gmonth + 1)) && (dd > parseInt(gdate)))
age = age + 1;
var m;
var n;
if (mm == 12) n = 31 - dd;
if (mm == 11) n = 61 - dd;
if (mm == 10) n = 92 - dd;
if (mm == 9) n = 122 - dd;
if (mm == 8) n = 153 - dd;
if (mm == 7) n = 184 - dd;
if (mm == 6) n = 214 - dd;
if (mm == 5) n = 245 - dd;
if (mm == 4) n = 275 - dd;
if (mm == 3) n = 306 - dd;
if (mm == 2) { n = 334 - dd; if (leapyear(yy)) n++; }
if (mm == 1) { n = 365 - dd; if (leapyear(yy)) n++; }
if (gmonth == 1) m = 31;
if (gmonth == 2) {
m = 59;
if (leapyear(gyear)) m++;
}
if (gmonth == 3)  { m = 90;  if (leapyear(gyear)) m++; }
if (gmonth == 4)  { m = 120; if (leapyear(gyear)) m++; }
if (gmonth == 5)  { m = 151; if (leapyear(gyear)) m++; }
if (gmonth == 6)  { m = 181; if (leapyear(gyear)) m++; }
if (gmonth == 7)  { m = 212; if (leapyear(gyear)) m++; }
if (gmonth == 8)  { m = 243; if (leapyear(gyear)) m++; }
if (gmonth == 9)  { m = 273; if (leapyear(gyear)) m++; }
if (gmonth == 10) { m = 304; if (leapyear(gyear)) m++; }
if (gmonth == 11) { m = 334; if (leapyear(gyear)) m++; }
if (gmonth == 12) { m = 365; if (leapyear(gyear)) m++; }
months = age * 12;
months += 12 - parseInt(mm);
months += gmonth;
totdays = (parseInt(age) * 365);
totdays += age / 4;
totdays = parseInt(totdays) + gdate + m + n;
if (gmonth == 1) p = 31 + gdate;
if (gmonth == 2) {
p = 59 + gdate;
if (leapyear(gyear)) m = m+1;
}
if (gmonth == 3)  { p = 90 + gdate;  if (leapyear(gyear)) p++; }
if (gmonth == 4)  { p = 120 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 5)  { p = 151 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 6)  { p = 181 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 7)  { p = 212 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 8)  { p = 243 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 9)  { p = 273 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 10) { p = 304 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 11) { p = 334 + gdate; if (leapyear(gyear)) p++; }
if (gmonth == 12) { p = 365 + gdate; if (leapyear(gyear)) p++; }
weeks = (age * 365) + n + p;
weeks = weeks / 7;
etcdays = parseFloat(weeks) - parseInt(weeks);
etcdays = Math.round(etcdays * 7);
weeks = parseInt(weeks);
etcdays += parseInt(age / 4);
if (etcdays > 7)
weeks += parseInt(etcdays / 7);
document.agecalc.timealive.value += "     or " + weeks + " Weeks old\n";
document.agecalc.timealive.value += "     or " + months + " Months old\n";
document.agecalc.timealive.value += "     or " + totdays + " days old\n";
var time = new Date();
ghour = time.getHours();
gmin = time.getMinutes();
gsec = time.getSeconds();
hour = ((age * 365) + n + p) * 24;
hour += (parseInt(age / 4) * 24);
document.agecalc.timealive.value += "     or " + hour + " Hours old\n";
var min = (hour * 60) + gmin;
document.agecalc.timealive.value += "     or " + min + " Minutes old\n";
sec = (min * 60) + gsec;
document.agecalc.timealive.value += "     or " + sec + " Seconds old";
mm = mm - 1;
var r;
if (mm == 0) r = 0;
if (mm == 1) r = 31;
if (mm == 2) { r = 59; if (leapyear(gyear)) m++; }
if (mm == 3)  { r = 90;  if (leapyear(gyear)) r++; }
if (mm == 4)  { r = 120; if (leapyear(gyear)) r++; }
if (mm == 5)  { r = 151; if (leapyear(gyear)) r++; }
if (mm == 6)  { r = 181; if (leapyear(gyear)) r++; }
if (mm == 7)  { r = 212; if (leapyear(gyear)) r++; }
if (mm == 8)  { r = 243; if (leapyear(gyear)) r++; }
if (mm == 9)  { r = 273; if (leapyear(gyear)) r++; }
if (mm == 10) { r = 304; if (leapyear(gyear)) r++; }
if (mm == 11) { r = 334; if (leapyear(gyear)) r++; }
mm = mm + 1;
r = parseInt(r) + parseInt(dd);

if ((mm >= (gmonth + 1)) && (dd > gdate)) {
bday = r - m - gdate;
}
else {
if ((leapyear(gyear)) && ((mm > 2) && (dd < 29))) {
a = 366;
} else {
a = 365;
}
bday = a + (r - m - gdate);
}
nhour = 24 - parseInt(ghour);
nmin = 60 - parseInt(gmin);
nsec = 60 - parseInt(gsec);
while (bday > 366) bday -= 365;
if (((bday == 366) && (leapyear(gyear)) || ((bday == 365) && (!leapyear(gyear))))) {
document.agecalc.timealive.value += "\n\nAnd, today is your birthday!";
} else {
document.agecalc.timealive.value += "\n\nAnd, your next birthday is in:\n"
+ bday + " days " + nhour + " hrs " + nmin + " mins " + nsec + " secs";
setTimeout("run()", 1000);
   }
}
function leapyear(a) {
if (((a%4 == 0) && (a%100 != 0)) || (a%400 == 0))
return true;
else
return false;
}
//  End -->
</script>

<form name=agecalc>
<table>
<tr><td align=center>
Birthday:  <select name=month size=1>
<option>January
<option>February
<option>March
<option>April
<option>May
<option>June
<option>July
<option>August
<option>September
<option>October
<option>November
<option>December
</select>

<select name=day size=1>
<option>1
<option>2
<option>3
<option>4
<option>5
<option>6
<option>7
<option>8
<option>9
<option>10
<option>11
<option>12
<option>13
<option>14
<option>15
<option>16
<option>17
<option>18
<option>19
<option>20
<option>21
<option>22
<option>23
<option>24
<option>25
<option>26
<option>27
<option>28
<option>29
<option>30
<option>31
</select>
<input type=text name=year size=4 maxlength=4>
<br>
<input type=button name=start value="Calculate" οnclick="run();"><br>
<br>
<textarea rows=12 cols=35 name=timealive></textarea>
</td></tr>
</table>
</form>


http://www.niftyadmin.cn/n/925561.html

相关文章

kyro序列化踩坑记——提供方DTO新增字段,依赖方则报错

背景 A服务通过dubbo调用B服务&#xff0c;序列化方式选择的是kryo&#xff0c;A服务和B服务同时依赖C工程的一个DTO。 C工程的DTO新增了一个字段&#xff0c;deploy了&#xff0c;B服务引了最新的依赖。但是A服务并没有。 此字段&#xff0c;A服务并使用不上&#xff0c;也不…

显示特殊节日

<html> <head> <title>显示特殊节日脚本</title> </head> <body> <div align"center">显示特殊节日&#xff0c;如“五一”</div> <SCRIPT languagejavascript> <!-- calendar new Date(); d…

学会享受寂寞,才能享受爱情

每个人生下来就在和“与世隔绝”作斗争&#xff0c;所以我们害怕寂寞&#xff0c;需要同伴&#xff0c;甚至渴望爱情。 实际上&#xff0c;爱情的作用在于&#xff1a;把一个人牢牢的绑在身边&#xff0c;让Ta陪伴自己。在一时或一世间&#xff0c;忘记寂寞。 所以&#xff0c;…

网站的停留时间

<html> <head> <title>显示你的客户在你的站点逗留了多久</title> </head> <body> <form nameforms> <font size3> <CENTER> <div aligncenter> <p> …

window.open的所有参数

【1、最基本的弹出窗口代码】 <SCRIPT LANGUAGE"javascript"> <!-- window.open (page.html) --> </SCRIPT> 【2、经过设置后的弹出窗口】 下面再说一说弹出窗口的设置。只要再往上面的代码中加一点东西就可以了…

synchronized的 偏向锁、轻量级锁、重量级锁的优缺点对比以及其适应场景

锁优点缺点适用场景偏向锁加锁和解锁不需要额外的消耗&#xff0c;和执行非同步方法相比仅存在纳秒级的差距如果线程间存在锁竞争&#xff0c;会带来额外的所撤销的消耗适用于只有一个线程访问同步块场景轻量级锁竞争的线程不会阻塞&#xff0c;提高了程序的响应速度如果始终得…

TreeView小知识

得到所有选择的节点(根据target区分) string insertQXLB ""; foreach (TreeNode t in TreeView1.CheckedNodes) { if (t.Target.ToString() ! "1") { …

CAS的优缺点

CAS&#xff0c;在Java并发应用中通常指CompareAndSwap或CompareAndSet&#xff0c;即比较并交换。 CAS是一个原子操作&#xff0c;它比较一个内存位置的值并且只有相等时修改这个内存位置的值为新的值&#xff0c;保证了新的值总是基于最新的信息计算的&#xff0c;如果有其他…