您的位置:首页 > Web前端 > JavaScript

javascript jsp页面动态显示系统时间 测试可用 多浏览器通过测试 (2)

2014-09-15 13:16 841 查看
<%@ 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>My JSP 'MyJsp.jsp' starting page</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">
-->

</head>
<script language="javascript">
function nowTime(ev,type){
/*
* ev:显示时间的元素
* type:时间显示模式.若传入12则为12小时制,不传入则为24小时制
*/
//年月日时分秒
var Y,M,D,W,H,I,S;
//月日时分秒为单位时前面补零
function fillZero(v){
if(v<10){v='0'+v;}
return v;
}
(function(){
var d=new Date();
var Week=['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
Y=d.getFullYear();
M=fillZero(d.getMonth()+1);
D=fillZero(d.getDate());
W=Week[d.getDay()];
H=fillZero(d.getHours());
I=fillZero(d.getMinutes());
S=fillZero(d.getSeconds());
//12小时制显示模式
if(type && type==12){
//若要显示更多时间类型诸如中午凌晨可在下面添加判断
if(H<=12){
H='上午'+H;
}else if(H>12 && H<24){
H-=12;
H='下午'+fillZero(H);
}else if(H==24){
H='下午00';
}
}
ev.innerHTML=Y+'年'+M+'月'+D+'日 '+''+W+''+H+':'+I+':'+S;
//每秒更新时间
setTimeout(arguments.callee,1000);
})();
}
</script>
<body onload="nowTime(nowtime,24);">
<p id="nowtime"></p>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: