JSP时间格式设置问题
用 <c:out> 提取表单的时间显示的JSP页面,但是时间格式无法设置,求高手解决!
代码:
<%@ page language= "java " pageEncoding= "GBK " contentType= "text/html;charset=GBK " %>
<%@ include file= "/common/taglibs.jsp "%>
<title> <fmt:message key= "contractList.title "/> </title>
<content tag= "heading "> <fmt:message key= "contractList.heading "/> </content>
<meta name= "menu " content= "ContractMenu "/>
<table cellpadding= "0 " class= "table contractList " cellspacing= "0 " id= "contractList " width= "100% ">
<tbody>
<c:forEach var= "contract " items= "${contractList} " >
<tr>
<td align= "left " width= "30% "> <a href= "/sfz/editContracts.html?id= <c:out value= "${contract.id} "/> &target=contract "> <c:out value= "${contract.createDate} "/> </a> </td>
</tr>
</c:forEach>
</tbody>
</table>
------解决方案--------------------在JSP里我没设置过时间格式,不过在JAVA程序里设置过,不知道能不能帮到你
Date now = new Date();
TimeZone timeZoneChina = TimeZone.getTimeZone( "Asia/Shanghai ");//获取时区
DateFormat df = new SimpleDateFormat( "MM/dd→HH:mm:ss ");//设置时间输出格式
df.setTimeZone(timeZoneChina);//设置系统时区
System.out.println(df.format(now));
上面那段代码运行后 ,最后输入的时间就是09/23→12:44:20
当然这个时间输出格式你也可以自己定义(MM/dd→HH:mm:ss,这个可以自己定义,HH:mm:ss,或者改成别的顺序都可以的...)