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