简易js网页实时时钟日历

<script language="javascript">
function timeF(i){ 
	if(i<10){ 
		i="0"+i;  
	} 
	return i; 
}
function showtime()
{
var today,hour,second,minute,year,month,date;
var strDate ;
today=new Date();
var n_day = today.getDay();
switch (n_day)
{
    case 0:{
      strDate = "星期日"
    }break;
    case 1:{
      strDate = "星期一"
    }break;
    case 2:{
      strDate ="星期二"
    }break;
    case 3:{
      strDate = "星期三"
    }break;
    case 4:{
      strDate = "星期四"
    }break;
    case 5:{
      strDate = "星期五"
    }break;
    case 6:{
      strDate = "星期六"
    }break;
    case 7:{
      strDate = "星期日"
    }break;
}
year = today.getFullYear();
month = today.getMonth()+1;
date = today.getDate();
hour = today.getHours();
minute =today.getMinutes();
second = today.getSeconds();
document.getElementById('time').innerHTML = year + "年" + month + "月" + date + "日  " + strDate +"  " + timeF(hour) + ":" + timeF(minute) + ":" + timeF(second); //显示时间
setTimeout("showtime();", 1000); //设定函数自动执行时间为 1000 ms(1 s)
}
</script>

<span id="time"></span><script language="javascript"> showtime();</script>


[removed] var my_time=new Date(); var my_year= my_time.getFullYear();//获取年 var my_month=my_time.getMonth()+1;//获取月 var my_day=my_time.getDate();//获取今天的号数 var my_week=my_time.getDay();//获取今天的星期 var my_hours=my_time.getHours();//获取小时 var dayfirst=7-(my_day-my_week-1)%7+1;//计算这个月一号是星期 var dayfirsts=dayfirst;//存储 function mydays(){//在日历面板写入值 var x=1; var mydays=my_month_day(my_year,my_month) document.getElementById("mymouthshow")[removed]=my_month; document.getElementById("myyearshow")[removed]=my_year; document.getElementById("mydayshow")[removed]=my_day; document.getElementById("myhourshow")[removed]=my_hours; for(dayfirst;dayfirst<dayfirsts+mydays;dayfirst++){ document.getElementById("labl"+dayfirst)[removed]=x; if(x==my_day-1){ var y=x+dayfirsts; document.getElementById("labl"+y).style.color="red"; } x++; } } function my_month_day(my_year,my_month){//计算每个月的时间,时间方法 var my_month_day; switch(my_month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: return my_month_day=31; break; case 2: if(my_year%4==0){ if(my_year0==0&&my;_year@0!=0){ return my_month_day=28; }else{ return my_month_day=29; } }else{ return my_month_day=28; }; break; default: return my_month_day=30; break; } } function my_yeay(my_year){//返回这一年有多少天 var my_year_days; if(my_year%4==0){ if(my_year0==0&&my;_year@0!=0){ return my_year_days=365; }else{ return my_year_days=366; } }else{ return my_year_days=365; }; } function myselects(){//在日期和月select写入值 var y=0; var z=0; for(var i=1900;i<2099;i++){ document.getElementById("myselect1").options[y]=new Option(i,i); y++; } for(var i=1;i<=12;i++){ document.getElementById("myselect2").options[z]=new Option(i,i); z++; } document.getElementById("myselect1").value=my_year; document.getElementById("myselect2").value=my_month; } function myselecte(){ dayfirst=7-(my_day-my_week-1)%7+1; var myyear_day=0; var myyears=parseInt(document.getElementById("myselect1").value); var mymouth=parseInt(document.getElementById("myselect2").value); if(myyears<=my_year-1){ for(var i=myyears+1;i<=my_year-1;i++){ myyear_day=myyear_day+my_yeay(i); } for(var x=12;x>=mymouth;x--){ myyear_day=myyear_day+my_month_day(myyears,x); } for(var y=1;y<my_month;y++){ myyear_day=myyear_day+my_month_day(my_year,y); } myyear_day=myyear_day+1; myyear_day=7-(myyear_day-dayfirst)%7+1; }else if(myyears>=my_year+1){ for(var i=myyears-1;i>=my_year+1;i--){ myyear_day=myyear_day+my_yeay(i); } for(var x=1;x<mymouth;x++){ myyear_day=myyear_day+my_month_day(myyears,x); } for(var y=12;y>=my_month;y--){ myyear_day=myyear_day+my_month_day(my_year,y); } myyear_day=myyear_day+1; myyear_day=(myyear_day-(7-dayfirst))%7-1; }else if(myyears=my_year){ if(mymouth>my_month){ for(var z=my_month;z<mymouth;z++){ myyear_day=myyear_day+my_month_day(myyears,z); } myyear_day=myyear_day+1; myyear_day=(myyear_day-(7-dayfirst))%7-1; }else if(mymouth<my_month){ for(var j=mymouth;j<my_month;j++){ myyear_day=myyear_day+my_month_day(myyears,j); } myyear_day=myyear_day+1; myyear_day=7-(myyear_day-dayfirst)%7+1; }else if(mymouth=my_month){ myyear_day=7-(my_day-my_week-1)%7+1; } } dayfirst=myyear_day; dayfirsts=myyear_day; mydayss(); } function mydayss(){//在日历面板写入值 var x=1; var myyears=parseInt(document.getElementById("myselect1").value); var mymouth=parseInt(document.getElementById("myselect2").value); var mydays=my_month_day(myyears,mymouth) document.getElementById("mymouthshow")[removed]=my_month; document.getElementById("myyearshow")[removed]=my_year; document.getElementById("mydayshow")[removed]=my_day; document.getElementById("myhourshow")[removed]=my_hours; for(var h=-1;h<=42;h++){ document.getElementById("labl"+h)[removed]=""; document.getElementById("labl"+h).style.color=""; } for(dayfirst;dayfirst<dayfirsts+mydays;dayfirst++){ document.getElementById("labl"+dayfirst)[removed]=x; if(x==my_day-1){ var y=x+dayfirsts; document.getElementById("labl"+y).style.color="red"; } x++; } } function myonload(){ myselects(); mydays(); } [removed]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值