输出时间最为简单的方式:
<%@page c%>
<%
java.util.Calendar rightNow = java.util.Calendar.getInstance();
out.print(rightNow.getTime()+"<p>");
%>
格式化时间:
<%@page c%>
<%
java.util.Calendar rightNow = java.util.Calendar.getInstance();
out.print("今年是"+rightNow.get(java.util.Calendar.YEAR)+"年<p>");
String[] monthOfYear={"一","二","三","四","五","六","七","八","九","十","十一","十二"};
out.print("月份是"+monthOfYear[rightNow.get(java.util.Calendar.MONTH)]+"月<p>");
out.print("日期是"+rightNow.get(java.util.Calendar.DATE)+"日<p>");
String[] dayOfWeek={"日","一","二","三","四","五","六"};
out.print("今天是星期"+dayOfWeek[rightNow.get(java.util.Calendar.DAY_OF_WEEK)-1]+"<p>");
out.print("现在是"+rightNow.get(java.util.Calendar.HOUR)+"小时"+rightNow.get(java.util.Calendar.MINUTE)+"分"+rightNow.get(java.util.Calendar.SECOND)+"秒"+"<p>");
%>
使用DateFormat完成的格式化时间:
<%@page c%>
<%
java.util.Calendar rightNow = java.util.Calendar.getInstance();
out.print(java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL).format(rightNow.getTime()));
%>
[此贴子已经被作者于2010-12-12 08:17:37编辑过]