電子時鐘.JPG


<HTML lang="zh-tw">
<HEAD>
<meta content="text/html; charset=Big5" http-equiv="content-type">


<TITLE>顯示現在時間</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function show_now() {
 
  var now = new Date();

  var hours = now.getHours();
  var minutes = now.getMinutes();
  var seconds = now.getSeconds();
 
  var timeValue = ((hours>12)?hours-12:hours);
  timeValue += ((minutes<10)?":0":":")+minutes
  timeValue += ((seconds<10)?":0":":")+seconds
  //分上午下午晚上凌晨
  if(hours>=6&&hours<=12){timeValue="上午" + timeValue}
  if(hours>12&&hours<=18){timeValue="下午" + timeValue}
  if(hours>18&&hours<=24){timeValue="晚上" + timeValue}
  if(hours<6){timeValue="凌晨"+ timeValue}

  document.f.now.value =timeValue;
  setTimeout('show_now()',1000);   //預約1秒鐘後再度呼叫 show_now()一次
}
</SCRIPT>

</HEAD>
<BODY onLoad="show_now()">
<form name='f'>
現在時間是:
<input type=text name='now' size=9.5>
<BR>
</form>

</BODY>
</HTML>


arrow
arrow
    全站熱搜

    阿賢 發表在 痞客邦 留言(0) 人氣()