JSP页显示当前日期的几种格式

JSP页显示当前日期的几种格式

一、第一种方式

[html]    
[head][title]取得系统时间[/title][/head]   
[body]   
[%java.util.Date date=new java.util.Date();%]    
现在是:<%=date%>    
[/body]    
[/html]    
运行结果:    
现在是:Tue Jul 31 10:32:52 CST 2001

二、第二种方式

[%@ page import="java.util.*, java.text.*" %]   
[HTML]    
[HEAD][TITLE]显示当前时间</TITLE][/HEAD]    
[BODY]   
当前时间:    
[%    
Date now = new Date();    
out.println(DateFormat.getTimeInstance().format(now));    
%]    
[/BODY]    
[/HTML]    
运行结果:    
10:31:42 AM  

三、第三种方式(个人偏向这种)

[%    
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy年MM月dd日");    
java.util.Date currentTime = new java.util.Date();    
out.print(formatter.format(currentTime));    
%]    
运行结果:    
2001年07月31日 

四、第四种方式

[%    
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy/MM/dd HH/mm/ss");    
java.util.Date currentTime_1 = new java.util.Date();    
out.print(formatter.format(currentTime_1));    
%]   
运行结果:    
2001/07/31 10/32/52