jstl <fmt:formatDate>标签
<fmt:formatDate>标记用于在各种不同的方式来格式化日期
属性:
<fmt:formatDate>标签具有以下属性:
属性 | 描述 | 必需 | 默认值 |
---|---|---|---|
value | 要显示的日期值 | Yes | None |
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 formatting pattern | No | None |
timeZone | Time zone of the displayed date | No | Default time zone |
var | Name of the variable to store the formatted date | No | Print to page |
scope | Scope of the variable to store the formatted date | No | page |
pattern属性来指定更精确的处理日期:
Code | Purpose | Sample |
---|---|---|
G |
The era designator |
AD |
y |
The year |
2002 |
M |
The month |
April & 04 |
d |
The day of the month |
20 |
h |
The hour(12-hour time) |
12 |
H |
The hour(24-hour time) |
0 |
m |
The minute |
45 |
s |
The second |
52 |
S |
The millisecond |
970 |
E |
The day of the week |
Tuesday |
D |
The day of the year |
180 |
F |
The day of the week in the month |
2 (2nd Wed in month) |
w |
The week in the year |
27 |
W |
The week in the month |
2 |
a |
The a.m./p.m. indicator |
PM |
k |
The hour(12-hour time) |
24 |
K |
The hour(24-hour time) |
0 |
z |
The time zone |
Central Standard Time |
' |
The escape for text |
|
'' |
The single quote |
例子:
<%@ 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 - www.yiibai.com</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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix