我需要只打印日期(年/月/日)但现在正在(日期/毫米/年和时间)

时间:2015-12-31 09:40:59

标签: jsp date datetime

<table border="0" cellpadding="0" cellspacing="0" width="460"  bgcolor="#EEFFCA">
<tr>
<td width="100%"><font size="6" color="#008000">&nbsp;Date Example</font>    </td>
</tr>
<tr>
<td width="100%"><b>&nbsp;Current Date and time is:&nbsp; <font  color="#FF0000">
<%= new java.util.Date() %>
</font></b></td>
</tr>
</table>

我需要以dd // mm / yyyy格式打印日期 我怎么能得到它

2 个答案:

答案 0 :(得分:1)

您可以使用SimpleDateFormat格式化输出:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
System.out.println(dateFormat.format(dateFormat.parse(<your date object>)));

答案 1 :(得分:0)

而不是

<%= new java.util.Date() %>

使用

<%= new SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date())%>

注意:您需要在jsp中导入SimpleDateFormat

<%@ page import="java.text.SimpleDateFormat" %>