这样将字符串型的数据转换为java里的date型?

tanyun1111 2004-09-04 06:52:44
我从oracle数据表中读出一date型数据,String time=rs.getString("TIME")
然后我想把它转换为java里的date型,不知怎么转换?谢谢
...全文
143 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
charlie0895 2004-09-06
  • 打赏
  • 举报
回复
方法很笨的,但真的不记得楼上说的那种简单方法是怎么写的了!
charlie0895 2004-09-06
  • 打赏
  • 举报
回复
String time = "2004-09-06 17:35:20";(这里和数据库里取出来是是一样的)
Date today = new Date();

today.setYear(Integer.parseInt(time.substring(0,4)));
today.setMonth(Integer.parseInt(time.substring(5,7)));
today.setDate(Integer.parseInt(time.substring(8,10)));
today.setHours(Integer.parseInt(time.substring(11,13)));
today.setMinutes(Integer.parseInt(time.substring(14,16)));
today.setSeconds(Integer.parseInt(time.substring(17,19)));
bobshi 2004-09-04
  • 打赏
  • 举报
回复
不好意思,写错了。:(
bobshi 2004-09-04
  • 打赏
  • 举报
回复
String time=rs.getString("TIME")


SimpleDateFormat simpleDFmt =new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");

simpleDFmt.format(time);
Drow 2004-09-04
  • 打赏
  • 举报
回复
String time = d.toGMTString()
再试
tanyun1111 2004-09-04
  • 打赏
  • 举报
回复
不行啊,rs.getDate("TIME")只能得到的时间是如:2004-09-04,而不能得到小时,分钟啊
Drow 2004-09-04
  • 打赏
  • 举报
回复
先java.util.Date d = rs.getDate("TIME")
再用Date类里的方法得到字符串。
有问题多查jdk,搞不定再问。
jimsons 2004-09-04
  • 打赏
  • 举报
回复
试下
java.util.Date time=rs.getDate("TIME");

81,122

社区成员

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

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