我的Action是这样的:
/**
* 新闻列表
*/
public ActionForward findAllNews(ActionMapping mapping, ActionForm form , HttpServletRequest request , HttpServletResponse response){
List<NewsForm> list = newsservice.getAll();
request.setAttribute(Contants.NEWS_LIST, list);
return mapping.findForward("newslist");
}在页面里是这样显示的:2010-04-20 00:00:00.0
可是结果返回的是集合,在这里我该怎么处理这个时间字段? 才能让他显示成 2010-04-20的呢?
请各位大虾帮帮忙
/**
* 新闻列表
*/
public ActionForward findAllNews(ActionMapping mapping, ActionForm form , HttpServletRequest request , HttpServletResponse response){
List<NewsForm> list = newsservice.getAll();
request.setAttribute(Contants.NEWS_LIST, list);
return mapping.findForward("newslist");
}在页面里是这样显示的:2010-04-20 00:00:00.0
可是结果返回的是集合,在这里我该怎么处理这个时间字段? 才能让他显示成 2010-04-20的呢?
请各位大虾帮帮忙
Date d = DateFormat.parse("你的日期字符串");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strd = sdf.format(d);
这里的getAll()方法中取得时间的时候,就在方法体中subString或者format了,然后直接从集合中取出值,这个值就是你要的了。
这个是用EL截取字符的。 你看看吧。 应该有帮助。。
明白?
用标签<c:foreach items="你的日期集合" var="time">
Date d = DateFormat.parse("time");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strd = sdf.format(d);