制作12小时进制的时钟

<body>
  <div id="time" style="color:#F00";></div>
  <script type="text/javascript" src="js/time.js"></script>
</body>

 

function showTime(){
	var time = new Date();
	var year = time.getFullYear();
	var month = time.getMonth()+1;
	var date = time.getDate();
	var hh = time.getHours();
	var mm = time.getMinutes();
	var ss = time.getSeconds();
	var day = time.getDay();	
	
	var type = "PM";
	if(hh<12)
		type="AM"
	
	if(hh<10)
		hh = "0"+hh;
	if(mm<10)
		mm = "0"+mm;
	if(ss<10)
		ss = "0"+ss;	
		
	var week = "";	
	switch(day){
		case 0:
			week = "星期日";
			break;
		case 1:
			week = "星期一";
			break;
		case 2:
			week = "星期二";
			break;
		case 3:
			week = "星期三";
			break;
		case 4:
			week = "星期四";
			break;
		case 5:
			week = "星期五";
			break;
		default:
			week = "星期六";
			break;
	}	
	var html = "<h3>你好,欢迎访问贵美商城!<br />"+year+"年"+month+"月"+date+"日&nbsp;"+hh+":"+mm+":"+ss+"&nbsp;"+type+"&nbsp;"+week+"</h3>";
	document.getElementById("time").innerHTML=html;
}


window.onload = function(){
	var obj = setInterval("showTime()",1000);
}

 

效果图:

 

个人E-mail:chaoyi77@163.com

 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值