<FMT:formatDate>标记用于格式的日期在一个多种方式。
<FMT:formatDate>标签具有以下属性-
| 属性 | 描述 | 需要 | 默认 |
|---|---|---|---|
| 值 | 要显示的日期值 | 是 | 没有 |
| 类型 | 日期,时间或两者 | 没有 | 日期 |
| dateStyle | 满,长,中,短或默认 | 没有 | 默认 |
| timeStyle | 满,长,中,短或默认 | 没有 | 默认 |
| 模式 | 自定义格式模式 | 没有 | 没有 |
| 时区 | 显示日期的时区 | 没有 | 默认时区 |
| 变种 | 存储格式化日期的变量名称 | 没有 | 打印到页面 |
| 范围 | 存储格式化日期的变量范围 | 没有 | 页 |
pattern属性用于指定日期的更精确处理-
| 码 | 目的 | 示例 |
|---|---|---|
| G | 时代代号 | 广告 |
| ÿ | 那一年 | 2002年 |
| 中号 | 这个月 | 4月&04 |
| d | 一个月中的某天 | 20 |
| H | 小时(12小时制) | 12 |
| H | 小时(24小时制) | 0 |
| 米 | 分钟 | 45 |
| s | 第二 | 52 |
| 小号 | 毫秒 | 970 |
| Ë | 星期几 | 星期二 |
| d | 一年中的一天 | 180 |
| F | 一个月中的星期几 | 2(每月第二个星期三) |
| w | 一年中的星期 | 27 |
| w ^ | 一个月中的星期 | 2 |
| 一种 | 上午/下午指示器 | 下午 |
| ķ | 小时(12小时制) | 24 |
| ķ | 小时(24小时制) | 0 |
| ž | 时区 | 中部标准时间 |
| ' | 文字逃脱 | |
| '' | 单引号 |
<%@ 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