Struts 2 日期处理
1.日期格式化
demo1
<s:textfield name="contact.birthDate" label="ContactBirthDate">
<s:param name="value">
<s:date name="contact.birthDate" format="yyyy-MM-dd" />
</s:param>
</s:textfield>
demo2
<input type="text" value="<s:date name="contact.birthDate" format="yyyy-MM-dd" />" />
2.使用日期控件
加入struts2-dojo-plugin
......
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-dojo-plugin</artifactId>
<version>${struts-version}</version>
</dependency>
......
To use this tag:
- Add: <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> to your page.
- The head tag must be included on the page, which can be configured for performance or debugging purposes.
- If the parseContent parameter for the head tag is false (it is false by default), then the id tag is required.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sx:head/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Save Contact</title>
<script type="text/javascript" src="scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<div align="center">
<h1>
<font color="red">Save Contact</font>
</h1>
<s:form action="saveContact">
<s:textfield name="contact.firstName" label="ContactFirstName"></s:textfield>
<s:textfield name="contact.lastName" label="ContactLastName"></s:textfield>
<sx:datetimepicker name="contact.birthDate" label="ContactBirthDate"
displayFormat="yyyy-MM-dd"></sx:datetimepicker>
<s:submit value="submit"></s:submit>
</s:form>
</div>
</body>
</html>

详细文档说明可以参考http://struts.apache.org/2.x/docs/datetimepicker.html