Jstl Long data conversion to date format

Source: Internet
Author: User
Tags dateformat tld

First, there is a web-inf under the establishment of a DATETAG.TLD

<?XML version= "1.0" encoding= "UTF-8"?>  <taglib>      <tlib-version>1.0</tlib-version>      <jsp-version>1.2</jsp-version>        <Tag>          <name>Date</name>          <Tag-class>Com.hoolai.pirates.football.util.DateTag</Tag-class>                  <body-content>Jsp</body-content>          <attribute>              <name>Value</name>              <Required>True</Required>              <Rtexprvalue>True</Rtexprvalue>          </attribute>      </Tag>  </taglib>

Second, create a new class DateTag

 PackageCom.hoolai.pirates.football.util;Importjava.io.IOException;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjavax.servlet.jsp.JspException;ImportJavax.servlet.jsp.tagext.TagSupport; Public classDateTagextendsTagSupport {Private Static Final LongSerialversionuid = -2312310581852395045l; PrivateString value; @Override Public intdoStartTag ()throwsjspexception {String VV= "" +value; LongTime =long.valueof (VV); Calendar C=calendar.getinstance ();        C.settimeinmillis (time); SimpleDateFormat DateFormat=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String s=Dateformat.format (C.gettime ()); Try{pagecontext.getout (). write (s); } Catch(IOException e) {e.printstacktrace (); }        return Super. doStartTag (); }     Public voidSetValue (String value) { This. Value =value; }}

Third, the introduction of the JSP

<%@ taglib prefix= "lzq" uri= "/web-inf/lib/tld/datetag.tld"%>  

Iv. where to go in the page

<align= "Left"><name= "EndTime"  Type= "text"  value= "<lzq:date value="${res.endtime} "/> "class=" Input_bg "/></td>

This is passed in the servlet is a long, on the page with JSTL can be formatted as 2015-02-06 23:26:22

Original: http://blog.csdn.net/li20040723/article/details/24996799

Jstl Long data conversion to date format

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.