JSTL的时间格式化标签的使用

j2ee项目中的前台页面展示后台数据时,一般会使用el和jstl表达式,那么时间数据从后台取出时显示的是util.date类型的格式,怎么才能转为正常我们所看到的格式呢?

下面是一些jstl中的<fmt:formatDate value="" type="both"/> 时间转化器:

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:parseDate value="${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"/>

2004-4-1 13:30:00  
<fmt:formatDate value="${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"/>

2004-4-1  
<fmt:formatDate value="${isoDate}"
type="time"/>

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

2004-5-31  
<fmt:formatDate value="${isoDate}" type="date"
dateStyle="short"/>

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

2004-5-31  
<fmt:formatDate value="${isoDate}" type="date"
dateStyle="long"/>

2004年5月31日  
<fmt:formatDate value="${isoDate}" type="date"
dateStyle="full"/>

2004年5月31日 星期一  
Attribute: timeStyle; optional. Varies the time
format. 
<fmt:formatDate value="${isoDate}" type="time"
timeStyle="default"/>

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

下午11:59  
<fmt:formatDate value="${isoDate}" type="time"
timeStyle="medium"/>

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

下午11时59分59秒  
<fmt:formatDate value="${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, MMMM d, yyyy HH:mm:ss
Z"/>

星期四, 四月 1, 2004 13:30:00
-0600  
<fmt:formatDate value="${isoDate}" type="both"
pattern="d MMM yy, h:m:s a zzzz

参考自:http://blog.sina.com.cn/ybx88

时间: 2024-12-18 03:11:52

JSTL的时间格式化标签的使用的相关文章

时间格式化标签

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %><%@ taglib uri="http://java.sun.co

jstl的时间日期格式化标签

后台: request.setAttribute("today",new Date()); 前台: <% taglib prefix="fmt" uri=http://java.sun.com/jsp/jstl/fmt %> <fmt:formatDate value="${today}" />             //不写type属性,和type="date"等价       结果: 2010-9

jsp自定义标签(时间格式化包括Long转时间)

1.jsp自带标签的格式化: jstl fmt 函数大全:主要针对格式化功能 Tags   fmt:requestEncoding fmt:setLocale fmt:timeZone fmt:setTimeZone fmt:bundle fmt:setBundle fmt:message fmt:param fmt:formatNumber fmt:parseNumber fmt:formatDate fmt:parseDate 先在jsp页面上增加: <%@ taglib uri="h

PHPCMS V9调用时间标签 |日期时间格式化

PHPCMS V9 如何调用时间标签,下面分享常见的调用时间标签 |日期时间格式化 1.日期时间格式化显示: a标准型:{date('Y-m-d H:i:s', $rs['inputtime'])} 输出为:2013-01-31 13:15:10 b拆分型:{date('Y',$rs[inputtime])}年{date('m',$rs[inputtime])}月{date('d',$rs[inputtime])}日 输出为:2013年01月31日 c扩展型: {date('Y',$inputt

(2)JSTL的fmt国际化标签库

format标签库:做国际化格式化,分两类 : 国际化核心标签:<fmt:setLocale>.<fmt:bundle>.<fmt:setBundle>.<fmt:message>.<fmt:param>.<fmt:requestEncoding> 格式化标签:<fmt:timeZone>.<fmt:setTimeZone>.<fmt:formatNumber>.<fmt:parseNumbe

织梦dedecms文章发布日期时间调用标签大全

dedecms首页时间标签: 1.12-27 样式 [field:pubdate function='strftime("%m-%d",@me)'/] 2.May 15, 2012 样式 [field:pubdate function='strftime("%b %d, %Y",@me)'/] dedecms列表页时间标签: 1.2012-08-20 18:30:02 样式: [field:pubdate function="GetDateTimeMK(@

dedecms时间日期标签大全

DEDECMS利用strftime()函数格式化时间的所有参数详解,包括年份日期进制.小时格式等 一:dedecms首页时间标签: 1.12-27 样式 ([field:pubdate function='strftime("%m-%d",@me)'/]) 2.May 15, 2009 样式 ([field:pubdate function='strftime("%b %d, %Y",@me)'/]) 提示:可修改后代码再运行! 二:dedecms列表页时间标签:

JQuery时间格式化插件--扩展JQuery

(function($){ $.formatDate = function(pattern,date){ //如果不设置,默认为当前时间 if(!date) date = new Date(); if(typeof(date) ==="string"){ if(date=="") date = new Date(); else date = new Date(date.replace(/-/g,"/")); } /*补00*/ var toFix

js对特殊字符转义、时间格式化、获取URL参数

/*特殊字符转义*/ function replace_html(str) { var str = str.toString().replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"'); return str; } /* *时间格式化 *例子:time = new Date().Format(