各位大侠好啊,小弟做了个jsp+javaBean来显示系统的时间啊,但时间那一栏就会出错啊,麻烦各位指出错在那里了啊程序如下:这个是Beanpackage test;import java.util.*;
import java.text.*;
/**
 *
 * @author Administrator
 */
public class CalendarBean {    Calendar calendar = null;    public CalendarBean() {
        calendar = Calendar.getInstance(TimeZone.getTimeZone("PST"));
        Date trialTime = new Date();
        calendar.setTime(trialTime);
    }    public int getYear() {
        return calendar.get(Calendar.YEAR);
    }    public String getMonth() {
        int m = getMonthInt();
        String months[] = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
        if (m > 12) {
            return "Unknown to month";
        }
        return months[m - 1];
    }    public int getMonthInt() {
        return calendar.get(Calendar.MONTH) + 1;
    }    public String getDay() {
        int x = getDayOfWeek();
        String[] days = new String[]{"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        if (x > 7) {
            return "Unknown to day";
        }
        return days[x - 1];
    }    public int getDayOfWeek() {
        return calendar.get(Calendar.DAY_OF_WEEK);
    }    public String getDate() {
        String year = String.valueOf(getYear());   //int----String的转换  
        return year + "-" + getMonth() + "-" + getDayOfMonth()+"-"+getDay();          //int i=integer.parseInt()  int i=Integer.valueOf(my_str).intValue()
    }    public int getDayOfMonth() {
        return calendar.get(Calendar.DAY_OF_MONTH);
    }    public String getTime() {
       String hour =String.valueOf(getHour()); 
       String second =String.valueOf(getSecond());  //int----String的转换 
        return hour+":"+getMinute()+":"+second;
    }    public int getHour() {
        return calendar.get(Calendar.HOUR_OF_DAY);
    }    public int getMinute() {
        return calendar.get(Calendar.MINUTE);
    }    public int getSecond() {
        return calendar.get(Calendar.SECOND);
    }    public int getDayOfYear() {
        return calendar.get(Calendar.DAY_OF_YEAR);
    }    public int getWeekOfYear() {
        return calendar.get(Calendar.WEEK_OF_YEAR);
    }    public int getWeekOfMonth() {
        return calendar.get(Calendar.WEEK_OF_MONTH);
    }
}下面是jsp的显示页面:
<%@page contentType="text/html" 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>JSP Page</title>
    </head>
    <body>
        <jsp:useBean id="calendar" scope="page" class="test.CalendarBean"></jsp:useBean>
        <ur>
            <li>Date of month is:<jsp:getProperty name="calendar" property="dayOfMonth"></jsp:getProperty>号
            <li>Year is:<jsp:getProperty name="calendar" property="year"></jsp:getProperty>
            <li>Month is:<jsp:getProperty name="calendar" property="month"></jsp:getProperty>月
            <li> Date is:<jsp:getProperty name="calendar" property="date"></jsp:getProperty>
            <li>Time is:<jsp:getProperty name="calendar" property="time"></jsp:getProperty>
            <li>Day of year is:<jsp:getProperty name="calendar"property="dayOfYear"></jsp:getProperty>
            <li>Week of year is:<jsp:getProperty name="calendar" property="weekOfYear"></jsp:getProperty>
            <li>day is:<jsp:getProperty name="calendar" property="day"></jsp:getProperty> 
        </ur>  
    </body>
</html>运行的时候其他的什么都ok啊,但就是时间,几点几分出错啊,并不是我运行的时候显示的时间啊

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【qunqun886】截止到2008-07-22 16:17:57的历史汇总数据(不包括此帖):
    发帖的总数量:3                        发帖的总分数:60                       每贴平均分数:20                       
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:2                        结贴的总分数:40                       
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:1                        未结的总分数:20                       
    结贴的百分比:66.67 %               结分的百分比:66.67 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主加油
      

  2.   

    貌似只有时间是不对的吧
    你用的是PST时区的
      

  3.   

      
    背景时钟[好大的钟][推荐][共1步]====1、以下是这个效果的全部代码。[最好从一个空页面开始]<html>
    <head>
    <TITLE>背景时钟</TITLE> 
    <script language=javaScript>
    <!--// 
    function clockon() {
    thistime= new Date()
    var hours=thistime.getHours()
    var minutes=thistime.getMinutes()
    var seconds=thistime.getSeconds()
    if (eval(hours) <10) {hours="0"+hours}
    if (eval(minutes) < 10) {minutes="0"+minutes}
    if (seconds < 10) {seconds="0"+seconds}
    thistime = hours+":"+minutes+":"+seconds
    if(document.all) {
    bgclocknoshade.innerHTML=thistime
    bgclockshade.innerHTML=thistime
    }
    if(document.layers) {
    document.bgclockshade.document.write('<div id="bgclockshade" style="position:absolute;visibility:visible;font-family:Verdana;color:FFAAAAA;font-size:120px;top:10px;left:152px">'+thistime+'</div>')
    document.bgclocknoshade.document.write('<div id="bgclocknoshade" style="position:absolute;visibility:visible;font-family:Verdana;color:DDDDDD;font-size:120px;top:10px;left:150px">'+thistime+'</div>')
    document.close()
    }
    var timer=setTimeout("clockon()",200)
    }
    //-->
    </script>
    <link rel="stylesheet" href="../style.css"></head>
    <body onLoad="clockon()">
    <div id="bgclockshade" style="position:absolute;visibility:visible;font-family:Arial;color:FF8888;font-size:120px;top:102px;left:152px"></div>
    <div id="bgclocknoshade" style="position:absolute;visibility:visible;font-family:Arial;color:DDDDDD;font-size:120px;top:100px;left:150px"></div>
    <div id="mainbody" style="position:absolute; visibility:visible">
    </div>
    </body>
    </html>
    说明:时钟显示的位置需要你修正TOP,LEFT参数来确定。TOP表示层距离显示器顶部的象素值,LEFT表示距离左侧的象素值。 
      
      
      

  4.   

    这种东西网上都的是,多用用baidu google把