1.网页采用javascript获取本地时间
[sourcecode language=”java” title=”demo-js.jsp”]</pre>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
var time = new Date();
document.write("从客户端传来问候!")
document.write("现在是北京时间:"+time.getHours()+"点,");
if(time.getHours()<11){
document.write("早上好!");}
else if(time.getHours()<13)
document.write("中午好!");
else if(time.getHours()<19)
document.write("下午好!");
else document.write("晚上好!");
</script>
</body>
</html>
<pre>
[/sourcecode]
效果图:
2.网页采用java代码获取服务器时间
[sourcecode language=”java” title=”demo.jsp”]
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" import="java.util.Date"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
Date time = new Date();
out.print("从服务器传来问候!\n");
out.print("现在是北京时间:"+time.getHours()+"点,");
if(time.getHours()<11){
out.print("早上好!");}
else if(time.getHours()<13)
out.print("中午好!");
else if(time.getHours()<19)
out.print("下午好!");
else out.print("晚上好!");
%>
</body>
</html>
[/sourcecode]
效果图: