JSTL FMT Format Time

Source: Internet
Author: User

The use of the FMT function is required in the JSP to introduce
<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jsp/jstl/fmt"%>


<fmt:formatdate value= "${item.expdate}" pattern= "Yyyy-mm-dd"/>
Reported Java.lang.IllegalArgumentException:Cannot convert 20131125 of type class java.lang.String to class Java.util.Date
Exception because ${item.expdate} is taken out as a string type and cannot be converted to a date type
The output will be normal as follows
<fmt:formatdate value= "<%=new Date ()%>" pattern= "Yyyy-mm-dd"/>


The workaround is to resolve the string to date before formatting the date.

<fmt:parsedate value= "${item.expdate}" var= "Yearmonth" pattern= "Yyyy-mm-dd"/>


<fmt:formatdate value= "${yearmonth}" pattern= "yyyy-mm"/><!--here the value can only be date type--

<c:> Label Description:

Background:

Request.setattribute ("Today", New Date ());

Front desk:

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

<fmt:formatdate value= "${today}"/>//Do not write type attribute, and type= "date" equivalent

<fmt:formatdate value= "${today}" type= "Time"/>//type default value is Date

<fmt:formatdate value= "${today}" type= "both"/>

<fmt:formatdate value= "${today}" datestyle= "short"/>

<fmt:formatdate value= "${today}" datestyle= "Medium"/>//datestyle= "Medium" is the default value

<fmt:formatdate value= "${today}" datestyle= "Long"/>

<fmt:formatdate value= "${today}" datestyle= "full"/>

<fmt:formatdate value= "${today}" pattern= "Yyyy/mm/dd HH:mm:ss"/>

<fmt:formatdate value= "${today}" pattern= "Yyyy/mm/dd HH:mm:ss" var= "D"/>

${D}

Results: 2010-9-20

13:03:35

2010-9-20 13:05:32

10-9-20

2010-9-20

September 20, 2010

Wednesday, September 20, 2010

2010/09/20 13:10:25

2010/09/20 13:10:56

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.