日期:2014-05-18  浏览次数:20762 次

在线等!怎么把SQL Server 2000中的timestamp类型的字段转换成时间格式显示出来
...
DateFormat   df   =   new   java.text.SimpleDateFormat( "yyyy/MM/dd ");
...
out.println(   df.format(rs.getTimestamp(4))   );  
...
报错
java.sql.SQLException:   [Microsoft][SQLServer   2000   Driver   for   JDBC]Unsupported   data   conversion.


------解决方案--------------------
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd ");
sdf.format(datetime)
------解决方案--------------------
你用强制转换试试 !!!
------解决方案--------------------
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTest {
public static void main(String[] args) throws ParseException{
Date myDate = new Date(System.currentTimeMillis());
// This time format is your local time format.
System.out.println(myDate.toString());
// Used the simple format to get the String you want .
// The valid string ,you can reference the JDK Doc
SimpleDateFormat sDateFormat = new SimpleDateFormat(
"yyyy-MM-DD HH:mm:ss ");
System.out.println(sDateFormat.format(myDate));
System.out.println(sDateFormat.format(sDateFormat.parse( "2006-07-11 16:51:29.747 ")));
}
}


LZ把这段代码运行下就知道怎么转换了
------解决方案--------------------
rs.getString(3)得到000000000000089B
------解决方案--------------------
我也用的SQLSERVER数据库,把TIMESTAMP类型字段的时间用getString得到没有报错
得到的是一串String如(2006-07-11 16:51:29.747), 然后你再按照我上面给你的程序把String转成Date再用给定的格式格式化就OK了,你大概没仔细看我写的程序

System.out.println(sDateFormat.format(sDateFormat.parse( "2006-07-11 16:51:29.747 ")));