数据库中YY:MM:DD HH:MM:SS 取出来的却是YY:MM:DD ??

welion2000 2003-03-24 06:44:13
存的时候
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = sdf.format(new Date());把date存入Access中文本字段

取得时候
gtime1=RS.getDate("guest_time");只有日期,没有时分秒
改成gtime1=RS.getString("guest_time");报错

Incompatible type for =. Can't convert java.lang.String to java.sql.Date.
gtime1=RS.getString("guest_time");
请问应该怎么取完整时间?
...全文
154 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
q_starry 2003-03-25
  • 打赏
  • 举报
回复
Date类型只可以保存年月日三个字段,小时分种秒被省略去了
Time类型则省略了年月日,可以把这两个加起来就行了
再者
你可以用其它类型试试例如TimeStamps,不过他精确到毫秒
welion2000 2003-03-24
  • 打赏
  • 举报
回复
有简单的方法吗?
hotenM 2003-03-24
  • 打赏
  • 举报
回复
我那是个时间类啊,很通用的
welion2000 2003-03-24
  • 打赏
  • 举报
回复
是String类型的,长度肯定够

hotenM(南京) 不会要搞这么复杂把,有简单一点的马?
qiri07 2003-03-24
  • 打赏
  • 举报
回复
mark楼上的
hotenM 2003-03-24
  • 打赏
  • 举报
回复
package com.hoten.util;
import java.util.*;
/**
* <p>Title: Time </p>
* <p>Description: </p>
* 此类主要用来取得本地系统的系统时间并用下面5种格式显示
* 1. YYMMDDHH 8位
* 2. YYMMDDHHmm 10位
* 3. YYMMDDHHmmss 12位
* 4. YYYYMMDDHHmmss 14位
* 5. YYMMDDHHmmssxxx 15位 (最后的xxx 是毫秒)
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: hoten </p>
* @author lqf
* @version 1.0
*/
public class CTime {
public static final int YYMMDDhhmmssxxx=15;
public static final int YYYYMMDDhhmmss=14;
public static final int YYMMDDhhmmss=12;
public static final int YYMMDDhhmm=10;
public static final int YYMMDDhh=8;
/**
* 取得本地系统的时间,时间格式由参数决定
* @param format 时间格式由常量决定
* @return String 具有format格式的字符串
*/
public static String getTime(int format){
StringBuffer cTime=new StringBuffer(15);
Calendar time=Calendar.getInstance();
int miltime=time.get(Calendar.MILLISECOND);
int second=time.get(Calendar.SECOND);
int minute=time.get(Calendar.MINUTE);
int hour=time.get(Calendar.HOUR_OF_DAY);
int day =time.get(Calendar.DAY_OF_MONTH);
int month=time.get(Calendar.MONTH)+1;
int year =time.get(Calendar.YEAR);
time=null;
if(format!=14){
if(year>=2000) year=year-2000;
else year=year-1900;
}
if(format>=2){
if(format==14) cTime.append(year);
else cTime.append(getFormatTime(year,2));
}
if(format>=4)
cTime.append(getFormatTime(month,2));
if(format>=6)
cTime.append(getFormatTime(day,2));
if(format>=8)
cTime.append(getFormatTime(hour,2));
if(format>=10)
cTime.append(getFormatTime(minute,2));
if(format>=12)
cTime.append(getFormatTime(second,2));
if(format>=15)
try {
java.lang.Thread.sleep(1);
}
catch (Exception ex) {
}
cTime.append(getFormatTime(miltime,3));

return cTime.toString().trim();
}
/**
* 产生任意位的字符串
* @param time 要转换格式的时间
* @param format 转换的格式
* @return String 转换的时间
*/
private static String getFormatTime(int time,int format){
StringBuffer numm=new StringBuffer(format);
int length=String.valueOf(time).length();

if(format<length) return null;

for(int i=0 ;i<format-length ;i++){
numm.append("0");
}
numm.append(time);
return numm.toString().trim();
}
}
xby45 2003-03-24
  • 打赏
  • 举报
回复
你的guest_time字段的类型是什么?如果是varchar的话,是不是他的长度不够?

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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