jstl中的日期格式化

news/2024/5/18 12:57:50 标签: jstl, jsp, 日期, 格式化

<%
   String strdate="2004/04/01";
   Date a=new Date(strdate);
   request.setAttribute("a",a);
 %>
 <fmt:formatDate pattern="【yyyy-MM-dd】" value="${a}" type="both"/>

 web.xml

 

  < jsp-config >
     
< taglib >
    
< taglib-uri > http://java.sun.com/jstl/fmt </ taglib-uri >
    
< taglib-location > /WEB-INF/fmt.tld </ taglib-location >
</ taglib >

< taglib >
    
< taglib-uri > http://java.sun.com/jstl/fmt-rt </ taglib-uri >
    
< taglib-location > /WEB-INF/fmt-rt.tld </ taglib-location >
</ taglib >

< taglib >
    
< taglib-uri > http://java.sun.com/jstl/core </ taglib-uri >
    
< taglib-location > /WEB-INF/c.tld </ taglib-location >
</ taglib >

< taglib >
    
< taglib-uri > http://java.sun.com/jstl/core-rt </ taglib-uri >
    
< taglib-location > /WEB-INF/c-rt.tld </ taglib-location >
</ taglib >

< taglib >
    
< taglib-uri > http://java.sun.com/jstl/sql </ taglib-uri >
    
< taglib-location > /WEB-INF/sql.tld </ taglib-location >
</ taglib >

< taglib >
    
< taglib-uri > http://java.sun.com/jstl/sql-rt </ taglib-uri >
    
< taglib-location > /WEB-INF/sql-rt.tld </ taglib-location >
</ taglib >

< taglib >
    
< taglib-uri > http://java.sun.com/jstl/x </ taglib-uri >
    
< taglib-location > /WEB-INF/x.tld </ taglib-location >
</ taglib >

< taglib >
    
< taglib-uri > http://java.sun.com/jstl/x-rt </ taglib-uri >
    
< taglib-location > /WEB-INF/x-rt.tld </ taglib-location >
</ taglib >
  
</ jsp-config >

 

 

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" %>

新版本的应该是 :  <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="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://www.niftyadmin.cn/n/1599716.html

相关文章

用c语言实现感知器算法,python实现感知器算法(批处理)

本文实例为大家分享了Python感知器算法实现的具体代码&#xff0c;供大家参考&#xff0c;具体内容如下先创建感知器类&#xff1a;用于二分类# -*- coding: utf-8 -*-import numpy as npclass Perceptron(object):"""感知器&#xff1a;用于二分类参照改写 htt…

Java中将上传的文件首页生成缩略图(先将上传的文件转成pdf,然后将pdf转成jpg)

1、首先将上传的非jpg&#xff0c;pdf格式的文件转成pdf&#xff0c;这个是采用OpenOffice进行转的&#xff0c;具体代码如下&#xff1a; private void officeToPdf(){ OpenOfficeConnection connection new SocketOpenOfficeConnection(8100); try { connection.connect();…

Test3.java(java homework)

2 编程打印下列图案(用循环)&#xff1b; * * * * * * * * * * * * * * * * * import java.util.*; public class Test3 { public static void main (String[] args) { Scanner in new Scanner(System.in); System.out.println("Input n:"); int n in.nextInt();…

W ndows10如何清理使用痕迹,Windows10怎么清除使用痕迹?

总会有不想让系统记录软件的最近打开项目和文件的时候&#xff0c;那么如何清除。Windows10的设置已经和以前7和8的设置完全不一样了。关于这个&#xff0c;刚开始的时候我也寻找了很久。下面这里就来告诉你这些设置在哪&#xff0c;上图。清除最近打开项目1、打开Windows10“设…

jstl中取map,其中map的key是一个对象,value是一个list

<c:forEach items"${map }" var"item"> //取得key中的属性 ${item.key.name }<c:forEach items"${item.value }" var"arti" > //遍历每个key对应的list </c:forEach> </c:forEach>

Test4.java(java homework)

3 编写程序&#xff0c;打印乘法口诀表&#xff1b; public class Test4 { public static void main (String[] args) { System.out.print("/t"); for(int i1; i<9; i) { System.out.print(i "/t"); } System.out.println(); for(int i1; i<9; i)…

前k个高频元素c语言,90年代初自己接了一个项目编写(汇编Z80单板机传呼机高频(发射机)POCSAG 编码系统)...

Arduino做BP机POCSAG编码程序&#xff0c;大顾问机&#xff0c;用串口助手发送字符&#xff0c;发送格式a1234567b信息(aN或P向位&#xff0c;1234567为呼机在7位地址码,b1-4,为铃声)如&#xff1a;N12345671测试&#xff01;Arduino源程序如下:#define uchar unsigned char#de…

Test5.java(java homework)

4 设有各不相同面值的人民币若干&#xff0c;编写一个计算机程序&#xff0c;对任意输入的一个金额&#xff0c;给出能够组合出这个值得最佳可能&#xff0c;要求使用币值的个数最少。 import java.util.*; public class Test5 { public static void main (String[] args) { …