<Fmt: formatDate> tag
<Fmt: formatDate> tag is used in different ways to format dates.
Syntax
<fmt:formatDate value="<string>" type="<string>" dateStyle="<string>" timeStyle="<string>" pattern="<string>" timeZone="<string>" var="<string>" scope="<string>"/>
Attributes
<Fmt: formatDate> tag has the following attributes:
Attributes | description | If necessary | Defaults |
---|---|---|---|
value | To date display | Yes | no |
type | DATE, TIME, or BOTH | no | date |
dateStyle | FULL, LONG, MEDIUM, SHORT, or DEFAULT | no | default |
timeStyle | FULL, LONG, MEDIUM, SHORT, or DEFAULT | no | default |
pattern | Custom format mode | no | no |
timeZone | Time zone display date | no | Default time zone |
var | Variable names store formatted dates | no | Displayed on the page |
scope | Range variable storage format log | no | page |
<Fmt: formatDate> tag format mode
Code | description | Examples |
---|---|---|
G | Sign of the times | AD |
y | Year without the century. If the year without the century is less than 10, it is displayed with no leading zero year. | 2002 |
M | Month figures. Month digit without leading zeros. | April & 04 |
d | Day of the month. Single-digit days without leading zeros. | 20 |
h | 12-hour hours. Single-digit hours without leading zeros. | 12 |
H | 24-hour hours. Single-digit hours without leading zeros. | 0 |
m | minute. Digit minutes will not have a leading zero. | 45 |
s | second. Digit seconds without leading zeros. | 52 |
S | millisecond | 970 |
E | which day | Tuesday |
D | The first few days of the year | 180 |
F | A month in the first few days of the week | 2 (second Wednesday of the month) |
w | R the first few weeks of the year | 27 |
W | The first weeks of the month | 2 |
a | am / pm indicator | PM |
k | Hour (12-hour clock) | twenty four |
K | Hour (24-hour clock) | 0 |
z | Time zone | Central Standard Time |
' | Escape text | |
'' | apostrophe |
Examples Demo
<%@ page language="java" contentType="text/html; charset=UTF-8" 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>JSTL fmt:dateNumber 标签</title> </head> <body> <h3>日期格式化:</h3> <c:set var="now" value="<%=new java.util.Date()%>" /> <p>日期格式化 (1): <fmt:formatDate type="time" value="${now}" /></p> <p>日期格式化 (2): <fmt:formatDate type="date" value="${now}" /></p> <p>日期格式化 (3): <fmt:formatDate type="both" value="${now}" /></p> <p>日期格式化 (4): <fmt:formatDate type="both" dateStyle="short" timeStyle="short" value="${now}" /></p> <p>日期格式化 (5): <fmt:formatDate type="both" dateStyle="medium" timeStyle="medium" value="${now}" /></p> <p>日期格式化 (6): <fmt:formatDate type="both" dateStyle="long" timeStyle="long" value="${now}" /></p> <p>日期格式化 (7): <fmt:formatDate pattern="yyyy-MM-dd" value="${now}" /></p> </body> </html>
Examples of the above operating results:
日期格式化: 日期格式化 (1): 11:19:43 日期格式化 (2): 2016-6-26 日期格式化 (3): 2016-6-26 11:19:43 日期格式化 (4): 16-6-26 上午11:19 日期格式化 (5): 2016-6-26 11:19:43 日期格式化 (6): 2016年6月26日 上午11时19分43秒 日期格式化 (7): 2016-06-26