---
title: "javascript显示时间"
author: "leeyb"
date: "2009-08-09T20:02:15Z"
tags: []
slug: "javascript"
draft: false
lastmod: "2009-08-09T20:03:11Z"
id: 443411
url: "https://leeyb.iteye.com/blog/443411"
---

```
<script language="javascript">
function showtime(){
	var day,hours,minutes,seconds,timeValue;
	now = new Date();
	if(now.getDay()==0) day = "星期日"
	if(now.getDay()==1) day = "星期一"
	if(now.getDay()==2) day = "星期二"
	if(now.getDay()==3) day = "星期三"
	if(now.getDay()==4) day = "星期四"
	if(now.getDay()==5) day = "星期五"
	if(now.getDay()==6) day = "星期六"
	
	ymd = now.getYear() + "年" + (now.getMonth() + 1 ) + "月" + now.getDate() + "日";
	hours = now.getHours();
	minutes = now.getMinutes();
	seconds = now.getSeconds();
	
	timeValue = ymd;
	timeValue += day;
	timeValue += hours+ ":";
	timeValue += ((minutes < 10) ? "0" : "") + minutes + ":";
	timeValue += ((seconds < 10) ? "0" : "") + seconds + "";
	clock.innerHTML = timeValue;
	setTimeout("showtime()",100);
}
</script>
<body onload="showtime()">
	<div id="clock"></div>
</body>
```