JSP jstl-core-<fmt:formatDate> 标记

  • jstl-core-<fmt:formatDate> 标记

    <fmt:formatDate>标记用于格式的日期在一个多种方式。
  • 属性

    属性 描述 必需 默认值
    Value 要显示的日期值 是 没有
    type DATE, TIME, 或 BOTH 否 date
    dateStyle FULL, LONG, MEDIUM, SHORT, 或者 DEFAULT 否 default
    timeStyle FULL, LONG, MEDIUM, SHORT, 或者 DEFAULT 否 default
    pattern 自定义格式模式 否 没有
    timeZone 显示日期的时区 否 默认时区
    var 存储格式化日期的变量名称 否 打印到页面
    scope 存储格式化日期的变量范围 否 page
    pattern属性用于指定日期的更精确处理-
    代码 目的 例子
    G 时代代号 AD
    y 那一年 2002
    M 这个月 April & 04
    d 一个月中的某天 20
    h 小时(12小时制) 12
    H 小时(24小时制) 0
    m 分钟 45
    s 第二 52
    S 毫秒 970
    E 星期几 Tuesday
    D 一年中的一天 180
    F 一个月中的星期几 2 (2nd Wed in month)
    w 一年中的星期 27
    W 一个月中的星期 2
    a 上午/下午 指示符 PM
    k 小时(12小时制) 24
    K 小时(24小时制) 0
    z 时区 中部标准时间
    '   文本转义
    ''   单引号
  • 示例

    
    <%@ 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>JSTL fmt:dateNumber Tag</title>
       </head>
    
       <body>
          <h3>Number Format:</h3>
          <c:set var = "now" value = "<% = new java.util.Date()%>" />
    
          <p>Formatted Date (1): <fmt:formatDate type = "time" 
             value = "${now}" /></p>
          
          <p>Formatted Date (2): <fmt:formatDate type = "date" 
             value = "${now}" /></p>
          
          <p>Formatted Date (3): <fmt:formatDate type = "both" 
             value = "${now}" /></p>
          
          <p>Formatted Date (4): <fmt:formatDate type = "both" 
             dateStyle = "short" timeStyle = "short" value = "${now}" /></p>
          
          <p>Formatted Date (5): <fmt:formatDate type = "both" 
             dateStyle = "medium" timeStyle = "medium" value = "${now}" /></p>
          
          <p>Formatted Date (6): <fmt:formatDate type = "both" 
             dateStyle = "long" timeStyle = "long" value = "${now}" /></p>
          
          <p>Formatted Date (7): <fmt:formatDate pattern = "yyyy-MM-dd" 
             value = "${now}" /></p>
    
       </body>
    </html>
    
    这将产生以下结果-
    
    Date Format:
    
    Formatted Date (1): 14:27:18
    
    
    Formatted Date (2): 23-Sep-2010
    
    
    Formatted Date (3): 23-Sep-2010 14:27:18
    
    
    Formatted Date (4): 23/09/10 14:27
    
    
    Formatted Date (5): 23-Sep-2010 14:27:18
    
    
    Formatted Date (6): 23 September 2010 14:27:18 GST
    
    
    Formatted Date (7): 2010-09-23