日期型数据显示在页面中和显示在excel中为什么格式不一样呢?
问题如题,我需要把页面上的数据导出到excel中,程序代码是一样的,只是把修改了 contentType="application/msexcel,再页面上时间数据格式为:2008-10-13 11:40:00.0,可是到了excel中,格式变为10/10/2008 17:2:0,ORACLE中的数据格式已经改为yyyy-mm-dd hh24:mi格式了。部分代码如下:
<%
//String date1="",date2="";
String date1=request.getParameter("date1");
String date2=request.getParameter("date2");
if ( date1==null||date2==null)
{ SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm" );
Date date=new Date();
date2 = formatter.format(date);
date1=date2;
}
%>
<body>
<table width=349 border="4" id="querytable" cellspacing="0" bordercolorlight="#99ccff" class="TD" align="center" >
<tr>
<td width="48%" height="23" bgcolor="#99ccff" ><div align="center" class="STYLE2">日期</div></td>
<td width="52%" height="23" bgcolor="#99ccff" ><div align="center" class="STYLE2"><%=canshu%></div></td>
</tr>
<%String sql;
Connection conn=((DatabaseDataSource)browseSession.getDataSource()).getConnection() ;
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY) ;
// sql=request.getParameter("query_sql");
String sql1="select rq,"+zdname+" from "+pingjunshujubiaoname+" where rq between to_date('"+date1+"','yyyy-mm-dd hh24:mi') and to_date('"+date2+"','yyyy-mm-dd hh24:mi') and zdid='"+zdid+"' order by rq asc";
ResultSet rs=st.executeQuery(sql1) ;
ResultSetMetaData metaData = rs.getMetaData();
while(rs.next()){
%>
<tr height="27">
<td height="31" class="STYLE2"><div align="center"><%=NullToSpace.getNullcheck(rs.getString(1))%> </div></td>
<td class="STYLE2"><div align="center"><%=NullToSpace.getNullcheck(rs.getString(2))%> </div></td>
</tr>
<%}%>
</table>