1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> 
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
  4. <html> 
  5.   <head> 
  6.     <title>JavaBiz.cn wikititle> 
  7.   head> 
  8.   <body> 
  9.     <c:set var="now" value="<%=new java.util.Date()%>" /> 
  10.     <table border="1" cellpadding="0" cellspacing="0" 
  11.     style="border-collapse: collapse" bordercolor="#111111" 
  12.     width="63%" id="AutoNumber2"> 
  13.       <tr> 
  14.         <td width="100%" colspan="2" bgcolor="#0000FF"> 
  15.           <p align="center"> 
  16.             <b> 
  17.               <font color="#FFFFFF" size="4">Formatting:  
  18.               <fmt:formatDate value="${now}" type="both" 
  19.               timeStyle="long" dateStyle="long" /> 
  20.               font> 
  21.             b> 
  22.           p> 
  23.         td> 
  24.       tr> 
  25.  
  26.       <tr> 
  27.         <td width="51%">formatDate type="time"td> 
  28.  
  29.         <td width="49%"> 
  30.           <fmt:formatDate type="time" value="${now}" /> 
  31.         td> 
  32.       tr> 
  33.       <tr> 
  34.         <td width="51%">type="date"td> 
  35.  
  36.         <td width="49%"> 
  37.           <fmt:formatDate type="date" value="${now}" /> 
  38.         td> 
  39.       tr> 
  40.       <tr> 
  41.         <td width="51%">type="both"td> 
  42.  
  43.         <td width="49%"> 
  44.           <fmt:formatDate type="both" value="${now}" /> 
  45.         td> 
  46.       tr> 
  47.       <tr> 
  48.         <td width="51%">type="both" dateStyle="default" 
  49.         timeStyle="default"td> 
  50.  
  51.         <td width="49%"> 
  52.           <fmt:formatDate type="both" dateStyle="default" 
  53.           timeStyle="default" value="${now}" /> 
  54.         td> 
  55.       tr> 
  56.       <tr> 
  57.         <td width="51%">type="both" dateStyle="short" 
  58.         timeStyle="short"td> 
  59.  
  60.         <td width="49%"> 
  61.           <fmt:formatDate type="both" dateStyle="short" 
  62.           timeStyle="short" value="${now}" /> 
  63.         td> 
  64.       tr> 
  65.       <tr> 
  66.         <td width="51%">type="both" dateStyle="medium" 
  67.         timeStyle="medium"td> 
  68.  
  69.         <td width="49%"> 
  70.           <fmt:formatDate type="both" dateStyle="medium" 
  71.           timeStyle="medium" value="${now}" /> 
  72.         td> 
  73.       tr> 
  74.       <tr> 
  75.         <td width="51%">type="both" dateStyle="long" 
  76.         timeStyle="long"td> 
  77.  
  78.         <td width="49%"> 
  79.           <fmt:formatDate type="both" dateStyle="long" 
  80.           timeStyle="long" value="${now}" /> 
  81.         td> 
  82.       tr> 
  83.       <tr> 
  84.         <td width="51%">type="both" dateStyle="full" 
  85.         timeStyle="full"td> 
  86.         <td width="49%"> 
  87.           <fmt:formatDate type="both" dateStyle="full" 
  88.           timeStyle="full" value="${now}" /> 
  89.         td> 
  90.       tr> 
  91.       <tr> 
  92.         <td width="51%">pattern="yyyy-MM-dd"td> 
  93.         <td width="49%"> 
  94.           <fmt:formatDate pattern="yyyy-MM-dd" value="${now}" /> 
  95.         td> 
  96.       tr> 
  97.     table> 
  98.   body> 
  99. html> 

运行界面如下: