网页设计大赛之获取实时时间
在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>
运行截图:
未对界面进行修改,仅实现功能