网页设计大赛之获取实时时间

在jsp中用javascript实现

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<input type="text" name="time" id="mypwd"> 
<script type="text/javascript">
  window.onload = function(){
    showTime();
  }
  
  function showTime(){
    var myDate = new Date();
    var year = myDate.getFullYear();
    var month = myDate.getMonth() + 1;
    var date = myDate.getDate();
    var dateArr = ["","",'','','','',''];
    var day = myDate.getDay();
    var hours = myDate.getHours();
    var minutes = formatTime(myDate.getMinutes());
    var seconds = formatTime(myDate.getSeconds());
  
    var systemTime = document.getElementById("time");
    systemTime.innerHTML = " " + year + "" + month +"" + date + "" +  " " + hours + ":" + minutes ;
    setTimeout("showTime()",500);
    document.getElementById("mypwd").value = document.getElementById("time").innerHTML;
  }
  
  //格式化时间:分秒。
  function formatTime (i){
    if(i < 10){
      i = "0" + i;
    }
    return i;
  }
  
  </script>
  <div id="time"></div>
</body>
</html>

运行截图:

 

 未对界面进行修改,仅实现功能

 

posted @ 2019-12-09 10:49  锦瑟流年3344  阅读(347)  评论(0编辑  收藏  举报