JSTL FMT Format Time

Source: Internet
Author: User
Tags java format

<%@ 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.com/jsp/jstl/core"prefix="C" %><HTML>     <Head>       <title>My JSP ' fmt.jsp ' starting page</title>     </Head>       <Body>      <C:setvar= "Salary"value= "3540.2301"/>      <C:setvar= "Total"value= "56225.2301"/>      <Fmt:setlocalevalue= "en_US"/>Currency:<Fmt:formatnumbervalue= "${salary}"type= "Currency"CurrencyCode= "USD"/><BR>percent:<Fmt:formatnumbervalue= "${salary/total}"type= "percent"maxfractiondigits= "4"/><BR>      <HR>      <Jsp:usebeanID= "Now"class= "Java.util.Date"></Jsp:usebean>      <Fmt:setlocalevalue= "ZH_CN"/>full--><fmt:formatdatevalue= "${now}"type= "both"Datestyle= "full"Timestyle= "full"/><BR>long--><fmt:formatdatevalue= "${now}"type= "both"Datestyle= "Long"Timestyle= "Long"/><BR>medium--><fmt:formatdatevalue= "${now}"type= "both"Datestyle= "Medium"Timestyle= "Medium"/><BR>default--><fmt:formatdatevalue= "${now}"type= "both"Datestyle= "Default"Timestyle= "Default"/><BR>short--><fmt:formatdatevalue= "${now}"type= "both"Datestyle= "Short"Timestyle= "Short"/><BR>     </Body></HTML>

Today is: <fmt:formatdate value= "${now}" pattern= "G yyyy year mm DD Day E"/><br>
Now: <fmt:formatdate value= "${now}" pattern= "a HH:mm:ss. S Z "/>
Results:
Today is: October 19, 2007 A.D. Friday
Now is: PM 20:04:11.484 CST

<%@ 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 would thrown an exception. This page does no error handling.

Input Parameters:
date:2004/04/01:13:30:00 Java Format:thu Apr 13:30:00 CST 2004
isodate:20040531t235959 Java Format:mon 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 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"/>

May 31, 2004
<fmt:formatdate value= "${isodate}" type= "date" datestyle= "full"/>

Monday, May 31, 2004
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 P.M. 59 sec
<fmt:formatdate value= "${isodate}" type= "Time" timestyle= "full"/>

11:59 P.M. 59 sec. CDT
Attribute:pattern; Optional. Inidcates Date/time Custom Patterns.
<fmt:formatdate value= "${date}" type= "both" pattern= "eeee, MMMM D, yyyy HH:mm:ss Z"/>

Thursday, April 1, 2004 13:30:00-0600
<fmt:formatdate value= "${isodate}" type= "both" pattern= "D MMM yy, h:m:s a zzzz/>

<fmt:formatdate value= "${here can put date and string}" pattern= "yyyy year mm month DD Day"/>

JSTL FMT Format Time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.