81,091
社区成员
发帖
与我相关
我的任务
分享
<%@page pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%!
StringBuffer buf=new StringBuffer(); //这里算全局申明不?
%>
<!--显示获取-->
<%
Date date=new Date();
Calendar c = Calendar.getInstance();
String strWords[]={"早上好","下午好","晚上好"};
int h = c.get(c.HOUR_OF_DAY);
int index = 0;
index = getTimeIndex(h);//调用提示出错
buf.append("林东平");
buf.append(strWords[index]);
buf.append("<br>");
buf.append("服务器时间为: "+date);
}
%>
<!--时间返回-->
<%=buf.toString()%>
<!--时间索引值获取--%>
<%!
int getTimeIndex(int h)
{
if(h>0 && h<12) return 0;
if(h>12 && h<18) return 1;
if(h>18 && h<24) return 2;
}
%>
<%@ page language="java" contentType="text/html; charset=gbk"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
StringBuffer buf=new StringBuffer();
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("a");
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String currenTime = simpleDateFormat.format(date);
String currenHour = simpleDateFormat1.format(date);
buf.append("林东平 ");
buf.append(currenTime);
buf.append("好<br>");
buf.append("服务器时间为: "+currenHour);
%>
<!--时间返回-->
<%=buf.toString()%>
</body>
</html>