JSP 动态时间 JavaScript

<%@ page language="java"  pageEncoding="utf-8"%>
<html>
 <head>
  <title>动态时间显示</title>
  <script language="javascript">
 function disptime()
 {
  var time= new Date();
  var year= time.getYear();
  var month = time.getMonth()+1;
  var d = time.getDate();
  var dd = time.getDay();
  var ddd = null;
  switch (dd)
     {
      case 0: ddd="星期日";break;
      case 1: ddd="星期一";break;
      case 2: ddd="星期二";break;
      case 3: ddd="星期三";break;
      case 4: ddd="星期四";break;
      case 5: ddd="星期五";break;
      default : ddd="星期六";break;
     }
  var hour=time.getHours();
  var minute=time.getMinutes();
  var second=time.getSeconds();
  
  if(minute<10)
   minute="0"+minute;
  if(second<10)
   second="0"+second;
  document.myform.myclock.value=year+"-"+month+"-"+d+" "+hour+":"+minute+":"+second+" "+ddd;
  var myTime= setTimeout("disptime();",1000);
  
 }
</script>
</head>

<body onload="disptime();">
<form id="myform" name="myform" method="post" action="">
  <input name="myclock" type="text" id="myclock" size="22"/>
</form>

</body>
</html> 




运行效果见附件

你可能感兴趣的:(JavaScript,html,jsp)