服务咨询热线13938255602

新闻动态

联系我们

农资王软件官网,农资王软件,农资王,农资软件,农资进销存管理软件---农资行业管理软件优秀品牌

手 机:13938255602
邮 箱:403860604@qq.com
电 话:010-62669888
地 址:海淀区上地三街东口中黎科技园3#-C401

javabean处理时间实例

发布时间:2024-07-20 21:08:46人气:

avaBean类:DateBean

 

 1 package com.liu.bean;
 2 
 3 import java.text.SimpleDateFormat;
 4 import java.util.Calendar;
 5 import java.util.Date;
 6 
 7 public class DateBean {
 8     private String date;
 9     private String week;
10     private Calendar calendar = Calendar.getInstance();
11     
12     public String getDate()
13     {
14         //获取当前时间
15         Date current = Calendar.getInstance().getTime();
16         SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH小时mm分ss秒");
17         date = format.format(current);
18         return date;
19     }
20     public String getWeek()
21     {
22         String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
23         int index = calendar.get(Calendar.DAY_OF_WEEK);
24         week = weeks[index-1];
25         return week;
26     }
27 }




DateBean.jsp页面

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%
 3 String path = request.getContextPath();
 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 5 %>
 6 
 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 8 <html>
 9   <head>
10     <base href="<%=basePath%>">
11     
12     <title>My JSP 'DateBean.jsp' starting page</title>
13     
14     
15 
16   </head>
17   
18   <body>
19     <jsp:useBean id="date" class="com.liu.bean.DateBean"></jsp:useBean>
20     <div align="center">
21     <jsp:getProperty property="date" name="date"/><br/>
22     <jsp:getProperty property="week" name="date"/>
23     </div>
24   </body>
25 </html>

13938255602