posts - 495,  comments - 11,  trackbacks - 0

日期输入页面:

dateInput.jsp

<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>

<title>Currency Formatting</title>
</head>
<body>


<form method="post" action="doDateInput.jsp">
Please enter your birthday:
<select name="month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

<select name="day">
<c:forEach begin="1" end="31" var="day">
<option><c:out value="${day}"/></option>
</c:forEach>
</select>
<select name="year">
<c:forEach begin="1930" end="2003" var="year">
<option><c:out value="${year}"/></option>
</c:forEach>
</select>
<input type="submit" value="Submit" />
</form>



</body>
</html>

日期处理页面:

doDateInput.jsp

<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>

<title>Currency Formatting</title>
</head>
<body>


<fmt:parseDate
     
var="date"
      parseLocale
="zh_CN"
      value
="${param.year}-${param.month}-${param.day}">
   
</fmt:parseDate>

<fmt:formatDate value="${date}" dateStyle="full"/>



</body>
</html>

提交后,显示结果诸如1930年11月1日 星期六

如果日期输入是en_US格式,也就是做以下改动

<select name="month">
<option value="Jan">January</option>
<option value="Feb">February</option>
<option value="Mar">March</option>
<option value="Apr">April</option>
<option value="May">May</option>
<option value="Jun">June</option>
<option value="Jul">July</option>
<option value="Aug">August</option>
<option value="Sep">September</option>
<option value="Oct">October</option>
<option value="Nov">November</option>
<option value="Dec">December</option>
</select>

则日期处理页面也要做想应改动

<fmt:parseDate
      var="date"
      parseLocale="en_US"
      value="${param.month} ${param.day}, ${param.year}">  

注意逗号后有一个空格,因为英文的日期格式为"May 25, 1997"
</fmt:parseDate>

posted on 2007-10-24 20:11 jadmin 阅读(91) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: