有关JSP显示时间的问题?(急)

来源:百度知道 编辑:UC知道 时间:2024/06/07 17:17:45
利用JSP往数据库里插入时间.从数据库里看时间是:2007-11-30 4:50:58说明插入时是没有问题的.
但我从JSP读出来的时间却是:从小时开始就是0了:比如:2007-11-30 0:00:00了.问问大虾该怎么样搞才可以读出的时间是:2007-11-30 4:50:58呢?希望给代码:谢谢!!!!
另外:我用 SimpleDateFormat sdf = new SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE);
sdf.applyPattern("yyyy年MM月dd日HH时mm分ss秒");
String timeStr = sdf.format(message.getDate().getTime());
这样读出来的时间是:2007年11月30日00时00分00秒 后面是0.
附添加和查看数据库的代码:
package com.lipeng.lp;

import com.lipeng.util.*;
import java.sql.*;
import java.util.*;

public class MessageBean {
private Connection conn;
public MessageBean(){
conn = DataBaseConnection.getConnection();
}

public void addMessage(MessageVO msg)throws Exception
{
try
{
PreparedStatement stm=conn.prepareStatement("insert into message values(?,?,?,?,?)");
stm.setString(1,msg.getTitle());
stm.setString(2,msg.getName());

我用你的运行完全正常,估计是你时间来源就有问题:
在调用之前,打印message.getDate()。

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Format {
public static void main(String[] args){

Date d = new Date();
SimpleDateFormat f = new SimpleDateFormat("",Locale.SIMPLIFIED_CHINESE);
f.applyPattern("yyyy年MM月dd日HH时mm分ss秒");
System.out.println(f.format(d));
}
}

---------运行结果----------
2007年11月30日16时34分14秒

Jsp?---
在这之前在控制台打印:
System.out.println(message.getDate());
String timeStr = sdf.format(message.getDate().getTime());

把message.setDate(result.getDate("time"));
改为:message.setDate(result.getString(TO_char("time,'YYYY-MM-DD HH24:MI:SS'")));
试试看,也不知道可不可以

一步步的调 看那地方把后面的时候给丢了 在换个方法就能解决啊 别人的环境和你那不一样的 没办法

///时间日期函数 function Ncdatetime() { today=new Date(); function initArray(){ t