日期:2014-05-16 浏览次数:20409 次
public class DateTag extends TagSupport { private static final long serialVersionUID = 6464168398214506236L; private String value; @Override public int doStartTag() throws JspException { String vv = ""+value; long time = Long.valueOf(vv); Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); SimpleDateFormat dateformat =new SimpleDateFormat("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 void setValue(String value) { this.value = value; } }
<?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.util.DateTag</tag-class> <body-content>JSP</body-content> <attribute> <name>value</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
<taglib> <taglib-uri>/tags</taglib-uri> <taglib-location>/WEB-INF/datetag.tld</taglib-location> </taglib>
<%@ taglib uri="/tags" prefix="date"%> <date:date value="${detail.sendTime}"/>