JSTL日期格式化用法

JSP Standard Tag Libraries
Formatting and Internationalization
Two form input parameters, 'date' and 'isoDate', are URL-encoded in the link leading to this page. 'isoDate' is formatted according to the ISO8601 standard.
Formatting of numbers and dates is based on the browser's locale setting. Formatting will change if you switch the default language setting from English to French or German, for example. (The browser needs to be restarted, too.)

Library import and parameter capturing:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<fmt:parseDate value="param.date"var="date"pattern="yyyy/MM/dd:HH:mm:ss><fmt:parseDatevalue="{param.isoDate}" var="isoDate" pattern="yyyyMMdd'T'HHmmss">

The input parameters must match the patterns, or the JSP will thrown an exception. This page does no error handling.

Input parameters:
Date:    2004/04/01:13:30:00  Java format: Thu Apr 01 13:30:00 CST 2004
isoDate: 20040531T235959      Java format: Mon May 31 23:59:59 CDT 2004

Dates
Tag Output
Attribute: value; required. Tag has no body.
<fmt:formatDate value="date"type="both"/>20044113:30:00<fmt:formatDatevalue="{isoDate}" type="both"/>

2004-5-31 23:59:59 
Attribute: type; optional. Indicates what to print: date, time, or both.
<fmt:formatDate value="date"type="date"/>200441<fmt:formatDatevalue="{isoDate}" type="time"/>

23:59:59 
Attribute: dateStyle; optional. Varies the date format.
<fmt:formatDate value="isoDate"type="date"dateStyle="default"/>2004531<fmt:formatDatevalue="{isoDate}" type="date" dateStyle="short"/>

04-5-31 
<fmt:formatDate value="isoDate"type="date"dateStyle="medium"/>2004531<fmt:formatDatevalue="{isoDate}" type="date" dateStyle="long"/>

2004年5月31日 
<fmt:formatDate value="isoDate"type="date"dateStyle="full"/>2004531Attribute:timeStyle;optional.Variesthetimeformat.<fmt:formatDatevalue="{isoDate}" type="time" timeStyle="default"/>

23:59:59 
<fmt:formatDate value="isoDate"type="time"timeStyle="short"/>11:59<fmt:formatDatevalue="{isoDate}" type="time" timeStyle="medium"/>

23:59:59 
<fmt:formatDate value="isoDate"type="time"timeStyle="long"/>115959<fmt:formatDatevalue="{isoDate}" type="time" timeStyle="full"/>

下午11时59分59秒 CDT 
Attribute: pattern; optional. Inidcates date/time custom patterns.
<fmt:formatDate value="date"type="both"pattern="EEEE,MMMMd,yyyyHH:mm:ssZ"/>,1,200413:30:000600<fmt:formatDatevalue="{isoDate}" type="both" pattern="d MMM yy, h:m:s a zzzz/>

posted @   勤快的懒羊羊  阅读(220)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示