jsp 编程显示日期 编写一个jsp程序 要求在页面上显示 xxxx年xx月xx日 星期x 几点几分 最好给出程序示例
展开全部
--这是一个完整的JSP页面, 你将它 保存在一个.jsp文件, 部署到tomcat中就可以了。
<%@ page language="java" import="java.util.*;
import java.text.*"
pageEncoding="utf-8"%>
<html>
<head>
<title>显示时间</title>
</head>
<%
Date date = new Date();
Calendar cal=Calendar.getInstance();
String dayOfWeekTime="";
int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK);
switch(dayOfWeek){
case 1:dayOfWeekTime="星期天";break;
case 2:dayOfWeekTime="星期一";break;
case 3:dayOfWeekTime="星期二";break;
case 4:dayOfWeekTime="星期三";break;
case 5:dayOfWeekTime="星期四";break;
case 6:dayOfWeekTime="星期五";break;
case 7:dayOfWeekTime="星期六";break;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeString = sdf.format(date);
%>
<body>
<h1>
当前系统时间是:<%=timeString%> <%=dayOfWeekTime %>
</h1>
</body>
</html>
<%@ page language="java" import="java.util.*;
import java.text.*"
pageEncoding="utf-8"%>
<html>
<head>
<title>显示时间</title>
</head>
<%
Date date = new Date();
Calendar cal=Calendar.getInstance();
String dayOfWeekTime="";
int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK);
switch(dayOfWeek){
case 1:dayOfWeekTime="星期天";break;
case 2:dayOfWeekTime="星期一";break;
case 3:dayOfWeekTime="星期二";break;
case 4:dayOfWeekTime="星期三";break;
case 5:dayOfWeekTime="星期四";break;
case 6:dayOfWeekTime="星期五";break;
case 7:dayOfWeekTime="星期六";break;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeString = sdf.format(date);
%>
<body>
<h1>
当前系统时间是:<%=timeString%> <%=dayOfWeekTime %>
</h1>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询