java.util.Date()显示的日期为如下格式:
Fri Nov 24 12:39:22 CST 2006
那么怎样显示如2006-11-24这种格式的日期呢?
代码是这样的:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Manage";
String user="sa";
String password="sa";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from Employee";
ResultSet rs=stmt.executeQuery(sql);
int i;
ResultSetMetaData rsmd=rs.getMetaData();
int numCols=rsmd.getColumnCount();
for(i=1;i<=numCols;i++){
if(i>1) out.print(" ");
out.print(rsmd.getColumnLabel(i));
}%> <br> <%
out.println("");
while(rs.next()) {
for(i=1;i<=numCols;i++){
if(i>1) out.print(" ");
out.print(rs.getString(i));
}%> <br> <%
out.println("");
}
out.print("数据库操作成功,恭喜你");%> <br>
现在的时间是: <%
out.print(new java.util.Date());
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
显示结果是:
Em_Id Em_Name
1001 丁武
1002 王飞
数据库操作成功,恭喜你
现在的时间是: Sat Nov 25 13:10:42 CST 2006
现在想把时间显示为:2006-11-25的形式,怎么搞?