网页日期时间代码
网页日期时间代码
2008年5月28日 星期三 13:09 农历戊子年 四月廿四 (带农历格式的日期时间代码)
function getlastmonthday(y,m)
{
m=m-1;
if(m==0) m=12;
if(m==2)
{
if(isleapyear(y)==1)
day=29;
else
day=28;
}
else if(m==1||m==3||m==5||m==7||m==8|m==10|m==12)
day=31;
else
day=30;
return(day);
}
function getmonthday(y,m)
{
if(m==2)
{
if(isleapyear(y)==1)
day=29;
else
day=28;
}
else if(m==1||m==3||m==5||m==7||m==8|m==10|m==12)
day=31;
else
day=30;
return(day);
}
function isleapyear(n)
{
if( (n%4==0&&n%100!=0) || n%400==0 )
return(1);
else
return(0);
}
function getyeardays(y)
{
if(isleapyear(y)==1)
return(366);
else
return(365);
}
function getpassdays(y1,m1,d1,y2,m2,d2)
{
y=y2-y1;
n=0;
if(y>=1)
{
for(k=y1+1;k<=y2-1;k++)
{
n=n+getyeardays(k);
}
n=n+getpassdays2(y1,m1,d1,12,31);
n=n+getpassdays2(y2,1,1,m2,d2)+1;
}
if(y==0)
{
n=n+getpassdays2(y1,m1,d1,m2,d2);
}
return(n);
}
function getpassdays2(y1,m1,d1,m2,d2)
{
m=m2-m1;
n=0;
if(m>=1)
{
for(i=m1+1;i<=m2-1;i++)
{
n=n+getmonthday(y1,i);
}
n=n+getmonthday(y1,m1)-d1;
n=n+d2;
}
if(m==0)
{
n=n+d2-d1;
}
return(n);
}
function getxqstr(xq)
{
switch(xq)
{
case 0:xqstr="星期日";break;
case 1:xqstr="星期一";break;
case 2:xqstr="星期二";break;
case 3:xqstr="星期三";break;
case 4:xqstr="星期四";break;
case 5:xqstr="星期五";break;
case 6:xqstr="星期六";break;
}
return(xqstr);
}
var t1=new Date('Jan 19,2008 23:45:19');
var year1 = t1.getYear();
if(year1<1900) year1=1900+year1;
var month1 = t1.getMonth()+1;
var day1 = t1.getDate();
var xq1 = t1.getDay();
var hh1 = t1.getHours();
var mm1 = t1.getMinutes();
var ss1 = t1.getSeconds();
var t2 = new Date();
var ss2 = t2.getSeconds();
ssc=ss1-ss2;
var year2 = year1;
var month2 = month1;
var day2 = day1;
var xq2 = xq1;
var hh2 = hh1;
var mm2 = mm1;
var ss2old;
var year3,month3,day3; //定义为全局变量
var hh3,mm3;
var isdispnl=0;
function disptime_axpj()
{
var t2 = new Date();
var ss2 = t2.getSeconds();
if(ss2-ss2old>2||ss2-ss2old<-2)
ss2=ss2old+1;
if(ss2==0)
{ mm2=mm2+1; }
else if(ss2>=60)
{ mm2=mm2+1; ss2=ss2-60; }
if(mm2>=60) { hh2=hh2+1; mm2=mm2-60; }
if(hh2>=24) { day2=day2+1; xq2=xq2+1; hh2=hh2-24; }
if(xq2>=7) { xq2=xq2-7; }
dd=getmonthday(year2,month2);
if(day2>dd)
{ month2=month2+1; if(month2==13) { month2=1; year2=year2+1; }
day2=day2-dd;
}
if(month2>=13) { year2=year2+1; month2=month2-12 ; }
year3 = year2;
month3 = month2;
day3 = day2;
var xq3 = xq2;
hh3 = hh2;
mm3 = mm2;
var ss3 = ss2+ssc;
if(ss3<0) { mm3=mm3-1; ss3=ss3+60; }
if(ss3>=60) { mm3=mm3+1; ss3=ss3-60; }
if(mm3<0) { hh3=hh3-1; mm3=mm3+60; }
if(mm3>=60) { hh3=hh3+1; mm3=mm3-60; }
if(hh3<0) { day3=day3-1; hh3=hh3+24; }
if(hh3>=24) { day3=day3+1; hh3=hh3-24; }
if(xq3<0) { xq3=xq3+7; }
if(xq3>=7) { xq3=xq3-7; }
if(day3<=0)
{
dd=getlastmonthday(year3,month3);
month3=month3-1; if(month3==0) { month3=12; year3=year3-1; }
day3=day3+dd;
}
dd=getmonthday(year3,month3);
if(day3>dd)
{ month3=month3+1; if(month3==13) { month3=1; year3=year3+1; }
day3=day3-dd;
}
if(month3<=0) { year3=year3-1; month3=month3+12; }
if(month3>=13) { year3=year3+1; month3=month3-12; }
if(mm3<=9) mm3="0"+mm3;
if(ss3<=9) ss3="0"+ss3;
document.getElementById("disp1").innerHTML=""+year3+"年"+month3+"月"+day3+"日";
document.getElementById("disp2").innerHTML=""+hh3+":"+mm3;
document.getElementById("disp3").innerHTML=""+getxqstr(xq2);
dispnl();
ss2old=ss2;
window.setTimeout("disptime_axpj()", 1000);
}
function dispnl()
{
isdispnl=1;
var ny=new Array(0,29,29,30,29,29,30,29,30,30,30,29,30 , 30,29,29,30,29,29,30,29,30,30,29,30 , 30,30,29,29,30 ,29,29,30,29,30,29,30,30);
var nlyearname=new Array("0","丁亥年","戊子年","己丑年");
var dxnum=new Array("0","一","二","三","四","五","六","七","八","九","十","十一","十二");
n=getpassdays(2007,2,18,year3,month3,day3);
i=1;
nlmonth=1;
nlyearno=1;
while(n-ny[i]>=0)
{
n=n-ny[i];
nlmonth=nlmonth+1;
if(nlmonth==13)
{ nlmonth=1; nlyearno=nlyearno+1; }
i=i+1;
}
nyn=nlyearname[nlyearno];
if(i>=30) nlmonth=nlmonth-1;
nlday=n+1;
nlmonth2=""+dxnum[nlmonth]+"月";
if(nlday<=10)
nlday2="初"+dxnum[nlday];
else if(nlday>=11&&nlday<=19)
nlday2="十"+dxnum[nlday-10];
else if(nlday==20)
nlday2="廿十";
else if(nlday>=21&&nlday<=29)
nlday2="廿"+dxnum[nlday-20];
else if(nlday==30)
nlday2="三十";
else
nlday2="";
document.getElementById("disp4").innerHTML=""+nyn+" "+nlmonth2+nlday2;
}
function dispxl()
{
isdispnl=0;
document.getElementById("disp1").innerHTML=""+month3+"月"+day3+"日";
document.getElementById("disp2").innerHTML=""+hh3+":"+mm3;
document.getElementById("disp3").innerHTML=""+getxqstr(xq2);
}
disptime_axpj();
2008年5月28日 星期三 13:09:09 (不带农历格式的日期时间代码)
农历 |
function getlastmonthday(y,m)
{
m=m-1;
if(m==0) m=12;
if(m==2)
{
if(isleapyear(y)==1)
day=29;
else
day=28;
}
else if(m==1||m==3||m==5||m==7||m==8|m==10|m==12)
day=31;
else
day=30;
return(day);
}
function getmonthday(y,m)
{
if(m==2)
{
if(isleapyear(y)==1)
day=29;
else
day=28;
}
else if(m==1||m==3||m==5||m==7||m==8|m==10|m==12)
day=31;
else
day=30;
return(day);
}
function isleapyear(n)
{
if( (n%4==0&&n%100!=0) || n%400==0 )
return(1);
else
return(0);
}
function getyeardays(y)
{
if(isleapyear(y)==1)
return(366);
else
return(365);
}
function getpassdays(y1,m1,d1,y2,m2,d2)
{
y=y2-y1;
n=0;
if(y>=1)
{
for(k=y1+1;k<=y2-1;k++)
{
n=n+getyeardays(k);
}
n=n+getpassdays2(y1,m1,d1,12,31);
n=n+getpassdays2(y2,1,1,m2,d2)+1;
}
if(y==0)
{
n=n+getpassdays2(y1,m1,d1,m2,d2);
}
return(n);
}
function getpassdays2(y1,m1,d1,m2,d2)
{
m=m2-m1;
n=0;
if(m>=1)
{
for(i=m1+1;i<=m2-1;i++)
{
n=n+getmonthday(y1,i);
}
n=n+getmonthday(y1,m1)-d1;
n=n+d2;
}
if(m==0)
{
n=n+d2-d1;
}
return(n);
}
function getxqstr(xq)
{
switch(xq)
{
case 0:xqstr="星期日";break;
case 1:xqstr="星期一";break;
case 2:xqstr="星期二";break;
case 3:xqstr="星期三";break;
case 4:xqstr="星期四";break;
case 5:xqstr="星期五";break;
case 6:xqstr="星期六";break;
}
return(xqstr);
}
var t1=new Date('Jan 19,2008 23:45:19');
var year1 = t1.getYear();
if(year1<1900) year1=1900+year1;
var month1 = t1.getMonth()+1;
var day1 = t1.getDate();
var xq1 = t1.getDay();
var hh1 = t1.getHours();
var mm1 = t1.getMinutes();
var ss1 = t1.getSeconds();
var t2 = new Date();
var ss2 = t2.getSeconds();
ssc=ss1-ss2;
var year2 = year1;
var month2 = month1;
var day2 = day1;
var xq2 = xq1;
var hh2 = hh1;
var mm2 = mm1;
var ss2old;
var year3,month3,day3; //定义为全局变量
var hh3,mm3;
var isdispnl=0;
function disptime_axpj()
{
var t2 = new Date();
var ss2 = t2.getSeconds();
if(ss2-ss2old>2||ss2-ss2old<-2)
ss2=ss2old+1;
if(ss2==0)
{ mm2=mm2+1; }
else if(ss2>=60)
{ mm2=mm2+1; ss2=ss2-60; }
if(mm2>=60) { hh2=hh2+1; mm2=mm2-60; }
if(hh2>=24) { day2=day2+1; xq2=xq2+1; hh2=hh2-24; }
if(xq2>=7) { xq2=xq2-7; }
dd=getmonthday(year2,month2);
if(day2>dd)
{ month2=month2+1; if(month2==13) { month2=1; year2=year2+1; }
day2=day2-dd;
}
if(month2>=13) { year2=year2+1; month2=month2-12 ; }
year3 = year2;
month3 = month2;
day3 = day2;
var xq3 = xq2;
hh3 = hh2;
mm3 = mm2;
var ss3 = ss2+ssc;
if(ss3<0) { mm3=mm3-1; ss3=ss3+60; }
if(ss3>=60) { mm3=mm3+1; ss3=ss3-60; }
if(mm3<0) { hh3=hh3-1; mm3=mm3+60; }
if(mm3>=60) { hh3=hh3+1; mm3=mm3-60; }
if(hh3<0) { day3=day3-1; hh3=hh3+24; }
if(hh3>=24) { day3=day3+1; hh3=hh3-24; }
if(xq3<0) { xq3=xq3+7; }
if(xq3>=7) { xq3=xq3-7; }
if(day3<=0)
{
dd=getlastmonthday(year3,month3);
month3=month3-1; if(month3==0) { month3=12; year3=year3-1; }
day3=day3+dd;
}
dd=getmonthday(year3,month3);
if(day3>dd)
{ month3=month3+1; if(month3==13) { month3=1; year3=year3+1; }
day3=day3-dd;
}
if(month3<=0) { year3=year3-1; month3=month3+12; }
if(month3>=13) { year3=year3+1; month3=month3-12; }
if(mm3<=9) mm3="0"+mm3;
if(ss3<=9) ss3="0"+ss3;
document.getElementById("disp1").innerHTML=""+year3+"年"+month3+"月"+day3+"日";
document.getElementById("disp2").innerHTML=""+hh3+":"+mm3;
document.getElementById("disp3").innerHTML=""+getxqstr(xq2);
dispnl();
ss2old=ss2;
window.setTimeout("disptime_axpj()", 1000);
}
function dispnl()
{
isdispnl=1;
var ny=new Array(0,29,29,30,29,29,30,29,30,30,30,29,30 , 30,29,29,30,29,29,30,29,30,30,29,30 , 30,30,29,29,30 ,29,29,30,29,30,29,30,30);
var nlyearname=new Array("0","丁亥年","戊子年","己丑年");
var dxnum=new Array("0","一","二","三","四","五","六","七","八","九","十","十一","十二");
n=getpassdays(2007,2,18,year3,month3,day3);
i=1;
nlmonth=1;
nlyearno=1;
while(n-ny[i]>=0)
{
n=n-ny[i];
nlmonth=nlmonth+1;
if(nlmonth==13)
{ nlmonth=1; nlyearno=nlyearno+1; }
i=i+1;
}
nyn=nlyearname[nlyearno];
if(i>=30) nlmonth=nlmonth-1;
nlday=n+1;
nlmonth2=""+dxnum[nlmonth]+"月";
if(nlday<=10)
nlday2="初"+dxnum[nlday];
else if(nlday>=11&&nlday<=19)
nlday2="十"+dxnum[nlday-10];
else if(nlday==20)
nlday2="廿十";
else if(nlday>=21&&nlday<=29)
nlday2="廿"+dxnum[nlday-20];
else if(nlday==30)
nlday2="三十";
else
nlday2="";
document.getElementById("disp4").innerHTML=""+nyn+" "+nlmonth2+nlday2;
}
function dispxl()
{
isdispnl=0;
document.getElementById("disp1").innerHTML=""+month3+"月"+day3+"日";
document.getElementById("disp2").innerHTML=""+hh3+":"+mm3;
document.getElementById("disp3").innerHTML=""+getxqstr(xq2);
}
disptime_axpj();
2008年5月28日 星期三 13:09:09 (不带农历格式的日期时间代码)
function timeprint() { var week; var date; var today=new Date() var year=today.getYear() var month=today.getMonth()+1 var day=today.getDate() var ss=today.getDay() var hours=today.getHours() var minutes=today.getMinutes() var seconds=today.getSeconds() date=year+"年"+month+"月"+day+"日 " if(ss==0) week="星期日" if(ss==1) week="星期一" if(ss==2) week="星期二" if(ss==3) week="星期三" if(ss==4) week="星期四" if(ss==5) week="星期五" if(ss==6) week="星期六" if(minutes<=9) minutes="0"+minutes if(seconds<=9) seconds="0"+seconds myclock=date+week+" "+hours+":"+minutes+":"+seconds if(document.layers){document.layers.liveclock.document.write(myclock) document.layers.liveclock.document.close() }else if(document.all) liveclock.innerHTML=myclock setTimeout("timeprint()",1000) } timeprint(); //--> |
您在这个论坛的权限:
您不能在这个论坛回复主题