日期型数据显示在页面中和显示在excel中为什么格式不一样呢?

happydaisy1985 2008-11-06 04:37:10
问题如题,我需要把页面上的数据导出到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>
...全文
242 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
happydaisy1985 2008-11-08
  • 打赏
  • 举报
回复
把...select rq...改成下面的试试看:
...select TO_CHAR(rq,'YYYY-MM-DD HH24:MI') RQ...

就会显示格式不匹配错误!
mantisXF 2008-11-06
  • 打赏
  • 举报
回复
把...select rq...改成下面的试试看:
...select TO_CHAR(rq,'YYYY-MM-DD HH24:MI') RQ...
[Quote=引用 2 楼 happydaisy1985 的回复:]
怎么指定格式?我用formatter.format(rs.getString(1));显示“意外的类型转换错误”我不知道该怎么写代码,给个具体指定显示格式的语句吧,很感谢!!
还有在页面上显示数据的代码和在excel中是一样的,可是确实两种不同的格式,怎么回事呢?页面上我也没有指定具体显示格式。况且默认格式应该是yyyy-mm-dd hh24:mi,我已经在oracle的注册表里修改过了。
[/Quote]
happydaisy1985 2008-11-06
  • 打赏
  • 举报
回复
怎么指定格式?我用formatter.format(rs.getString(1));显示“意外的类型转换错误”我不知道该怎么写代码,给个具体指定显示格式的语句吧,很感谢!!
还有在页面上显示数据的代码和在excel中是一样的,可是确实两种不同的格式,怎么回事呢?页面上我也没有指定具体显示格式。况且默认格式应该是yyyy-mm-dd hh24:mi,我已经在oracle的注册表里修改过了。
mantisXF 2008-11-06
  • 打赏
  • 举报
回复
如果不指定格式就会以默认格式显示。[Quote=引用楼主 happydaisy1985 的帖子:]
问题如题,我需要把页面上的数据导出到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"…
[/Quote]

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧