一尘不染

如何使用jstl在jsp的日历类型方法中获取日期设置?

jsp

我正在使用执行查询

select lastlevel as VERSION,name as DESCRIPTION,
TO_DATE(lastdate, 'DDMONYYYY_HH24:MI:SS') as RELEASEDATE
from mytable where rownum<=10

这列lastdate是varchar类型

得到这样的结果

Version     Release Date        
1.0         2002-11-22

2.0     2003-02-08

我在这里设置上述查询的结果,这里setLastDate是日历类型,所以我在类似方法中设置发布日期的结果

if (rs.getString("VERSION") != null ) {             bean.setLastLevel(rs.getString("VERSION").trim());
}

if (rs.getDate("RELEASEDATE") != null ) 
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(rs.getDate("RELEASEDATE"));
bean.setLastDate(calendar);
}

像2003-02-08这样在bean中设置该值。最后,我将这个结果bean添加到数组列表“ list”中,例如list.add(bean);。

现在我想在jsp中使用所有这些值。我正在使用spring mvc,所以我用arraylist“ list”返回视图。当我像这样迭代jsp中的值时

<c:forEach var="list" items="${list}">
<td valign="top">${list.lastLevel}</td>
<td valign="top">${list.lastDate}</td>
</c:forEach>

在jsp而不是获取日期,我越来越像这样

Version     Release Date        
1.0          java.util.GregorianCalendar[time=1037775600000,areFieldsSet=true,

areAllFieldsSet = true,lenient = true,zone = sun.util.calendar.ZoneInfo [id =“
US / Arizona”,offset = -25200000,dstSavings = 0,useDaylight =
false,transitions = 12,lastRule = null],firstDayOfWeek =
1,minimalDaysInFirstWeek = 1,ERA = 1,YEAR = 2002,MONTH = 10,WEEK_OF_YEAR =
47,WEEK_OF_MONTH = 4,DAY_OF_MONTH = 20,DAY_OF_YEAR = 324,DAY_OF_WEEK =
4,DAY_OF_WEEK_IN_MONTH = 3,AM_PM = 0,HOUR = 0, HOUR_OF_DAY = 0,MINUTE =
0,SECOND = 0,MILLISECOND = 0,ZONE_OFFSET = -25200000,DST_OFFSET = 0]

2.0          java.util.GregorianCalendar[time=1044687600000,areFieldsSet=true,
areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="US/Arizona",offset=-25200000,dstSavings=0,useDaylight=false,transitions=12,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2003,MONTH=1,WEEK_OF_YEAR=6,WEEK_OF_MONTH=2,DAY_OF_MONTH=8,DAY_OF_YEAR=39,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=2,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-25200000,DST_OFFSET=0]

请帮我解决这个问题。我需要得到结果的日期。如何解决这个问题。提前致谢。


阅读 375

收藏
2020-06-10

共1个答案

一尘不染

采用

<td valign="top">${list.lastDate.time}</td>

它将getTime()在日历实例上调用方法,该方法返回Date实例

最好不要使用与该属性相同的var名称,而先调用它row(或其他有意义的变量名称),然后${row.lastDate.time}

<c:forEach var="row" items="${list}">
</c:forEach>

如果要自定义格式输出,则

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

并像这样使用

<fmt:formatDate pattern="yyyy-MM-dd"  value="${list.lastDate.time}" />
2020-06-10