用javaBean 显示系统时间

datebean

package itcast;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateBean {
	private String dateTime;
	private String week;
	private Calendar calendar = Calendar.getInstance();

	/**
	 * 获取当前日期和时间
	 * 
	 * @return 日期及时间字符串
	 */
	public String getDateTime() {
		Date currDate = Calendar.getInstance().getTime();
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy 年 MM 月 dd 日      HH 点 mm 分 ss 秒 ");
		dateTime = sdf.format(currDate);
		return dateTime;
	}

	/**
	 * 获取星期几
	 * 
	 * @return 返回星期几字符串
	 */
	public String getWeek() {
		String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		int index = calendar.get(Calendar.DAY_OF_WEEK);
		week = weeks[index - 1];
		return week;
	}
}

index.jsp

 


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
	errorPage="error.jsp"%>
<%
	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 'error.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>
<style type="text/css">
#clock {
	width: 420px;
	height: 80px;
	background: #E0E0E0;
	font-size: 25px;
	font-weight: bold;
	border: solid 5px orange;
	padding: 20px;
}

#week {
	padding-top: 15px;
	color: #0080FF;
}
</style>
<meta http-equiv="Refresh" content="1"><%-- 刷新界面 --%>
<body>
	<jsp:useBean id="date" class="itcast.DateBean" scope="application"></jsp:useBean>
	<div align="center">
		<div id="clock">
			<div id="time">
				<jsp:getProperty property="dateTime" name="date" />
			</div>
			<div id="week">
				<jsp:getProperty property="week" name="date" />
			</div>
		</div>
	</div>

</body>
</html>















 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值