본문 바로가기

디지털 시계

by xfree302 2009. 12. 15.
반응형


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<script language="JavaScript">
//현재 시간 나타내기
 function tick() {
  var ap, hours, minutes, seconds;
  var intHours, intMinutes, intSeconds, intYear, intMonth, intDate;
  var today;
  
  today = new Date();
  
  intHours = today.getHours();
  intMinutes = today.getMinutes();
  intSeconds = today.getSeconds();
  intYear = today.getYear();
  intMonth = today.getMonth();
  intDate = today.getDate();
  
  if (intHours == 0) {
  hours = "12:";
  ap = "AM ";
  } else if (intHours < 12) {
  hours = intHours+":";
  ap = "AM ";
  } else if (intHours == 12) {
  hours = "12:";
  ap = "PM ";
  } else {
  intHours = intHours - 12
  hours = intHours + ":";
  ap = "PM ";
  }
  
  if (intMinutes < 10) {
  minutes = "0"+intMinutes+":";
  } else {
  minutes = intMinutes+":";
  }
  
  if (intSeconds < 10) {
  seconds = "0"+intSeconds+"  ";
  } else {
  seconds = intSeconds+"  ";
  }
 
  year = " "+intYear;
 
  intMonth = intMonth + 1
  if (intMonth < 10 ) {
   month = "0"+intMonth;
  } else {
   month = ""+intMonth;
  }
  
  if (intDate < 10 ) {
   date = "0"+intDate;
  } else {
   date = ""+intDate;
  }
  oTimeDiv.innerHTML = ap;
  oDate.innerHTML = year + "-" + month + "-" + date;
  oTime.innerHTML = hours + minutes + seconds;
  
  window.setTimeout("tick();", 100);    //tick()함수를 1초에 한번씩 호출한다.
 }
  
 window.onload = tick;
</script>
<style type="text/css">
<!--
.lcd {  background-color: #BFBFBf; border: 1px #6699FF}
.txtTime { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 10pt; font-weight: bold; color: #666666; }
.txtDate { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 5pt; font-weight: bold; color: #666666; }
.txtTimeDiv { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 5pt; font-weight: bold; color: #666666; }
-->
</style>
</head>
 
<body bgcolor="#FFFFFF" text="#000000">
<table width="80" class="lcd" cellpadding="0" cellspacing="0">
  <tr>
 <td width="15" align="center">
<div id="oTimeDiv" class="txtTimeDiv"></div></td>
 <td><div id="oTime" class="txtTime"></div></td>
</tr>
<tr>
 <td colspan="2"><div id="oDate" class="txtDate"></div></td>
</tr>
</table>
</body>
</html>

 

반응형

'' 카테고리의 다른 글

aptana 웹제작툴(html, js, css ..)  (0) 2010.10.12
부모창 존재 여부  (0) 2010.01.14
기존 팝업창 닫고 다시 띄우기  (0) 2009.11.18
자바스크립트에서 이벤트 생성  (0) 2009.11.10
iframe 높이 자동 리사이즈  (0) 2009.11.10