简体   繁体   English

定制标签库JSP

[英]Custom Tag Librarys JSP

So I have a custom tag that currently works, but I would like to change it from the current date to show the date and the current time. 因此,我有一个自定义标签,该标签当前有效,但是我想将其从当前日期更改为显示日期和当前时间。

this is what I have as an output Current Date/Time: Monday, March 31, 2014 这是我的输出结果Current Date/Time: Monday, March 31, 2014

This is my tag 这是我的标签

<%@ tag language="java" pageEncoding="ISO-8859-1"%>
<%@ tag import="java.util.Date" import="java.text.DateFormat"%>

<%
    DateFormat dateFormat = 
            DateFormat.getDateInstance(DateFormat.FULL);
    Date now = new Date(System.currentTimeMillis());
    out.println(dateFormat.format(now));

%>

If you want the time as well use the getDateTimeInstance() method or for more flexibility use the SimpleDateFromat 如果还需要时间,请使用getDateTimeInstance()方法,或者为了获得更大的灵活性,请使用SimpleDateFromat

http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

By the way, the Date constructor new Date () will obtain the current date, you do not need to pass System.currentTimeMillis() 顺便说一下,Date构造函数new Date ()将获取当前日期,您无需传递System.currentTimeMillis()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM