页面显示时间

//页面显示时间

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme()+"://"+request.getServerName()
  +":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>">
  <title>当前时间显示页面</title>
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
  <script type="text/javascript">
 function showtime()
  {
  var hour,second,minute,year,month,date;
  var strDate;
  var today=new Date();
  var n_day = today.getDay();
  switch(n_day)
  {
   case 0:
   {
    strDate = "星期日";
   }
   break;
   case 1:
   {
    strDate = "星期一";
   }
   break;
   case 2:
   {
    strDate ="星期二";
   }
   break;
   case 3:
   {
    strDate = "星期三";
   }
   break;
   case 4:
   {
    strDate = "星期四";
   }
   break;
   case 5:
   {
    strDate = "星期五";
   }
   break;
   case 6:
   {
    strDate = "星期六";
   }
   break;
   case 7:
   {
    strDate = "星期日";
   }
   break;
  }
    year = today.getFullYear(); //年
    month = today.getMonth()+1; //月
    date =today.getDate(); //日
    hour = today.getHours();//时
    minute =today.getMinutes();//分
    second = today.getSeconds(); //秒
    if(eval(hour)<10){hour="0"+hour;}
    if(eval(minute)<10){minute="0"+minute;}
    if(eval(second)<10){second="0"+second;}
    document.getElementById('time').innerHTML="&nbsp;&nbsp;&nbsp;"+year + "年" + month + "月" + date + "日&nbsp;" +strDate+""+hour+"时"+minute+"分"+second+"秒"; //显示时间
    setTimeout("showtime();", 1000); //设定函数自动执行时间为 1000ms(1 s)
}
 </script>
 </head>
 <body onload="showtime();">
  <table>
   <tr>
    <td>
     <div id=time
      style="font-size: 24px; height 20px; color: highlight; background-color: #ffddaa;"></div>
    </td>
   </tr>
  </table>
 </body>
</html>

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