简单的类型转换问题

cuilupeng999 2004-10-13 05:52:43
String start = "";
DbOperator dbp = new DbOperator();
ResultSet rs = null;
String sql = "select accept_date from xu_qcdl_basic where agent_code=" + qId + "";
// String caseName = "";
try {
rs = dbp.exeSingleSearch(sql);
if (rs != null) {
while (rs.next()) {
start = rs.getString("accept_date");
}
}
}
catch (Exception e) {
log.error(e.getMessage());
throw new RuntimeException("error.user.unexpect");
}
/////////////////////////////////////////
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/d");
Date startDate = sdf.parse(start);
上面的start类型和下面的转换不匹配,我要用下面的类型,请问上面怎么改
...全文
103 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
debug148 2004-10-13
  • 打赏
  • 举报
回复
ding
Query1981 2004-10-13
  • 打赏
  • 举报
回复
用Timestamp代替可以吗??这样只格式化string就可以了,再说与数据库交流的的话,应该用Timestamp的。

try{
String s1 = "2004-05-14 15:12:23" ;
Timestamp d1 = Timestamp.valueOf(s1) ;
System.out.println(d1);
}catch(Exception e)
{
e.printStackTrace();
}
lovesst 2004-10-13
  • 打赏
  • 举报
回复
public class t{
public static void main(String[]args)
{

String start="2004-09-08";
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat format1=new SimpleDateFormat("yyyy/MM/dd");
Date date=null;
Date startDate=null;
try
{
date=format.parse(start);//将串转为表中的日期格式
startDate=format1.parse(format1.format(date));//将该日期格式转为所需格式
String date1 = format1.format(startDate);
System.out.println(date1);

}
catch(Exception e)
{
}


}
}
GJA106 2004-10-13
  • 打赏
  • 举报
回复
1.自己写代码来转换成指定格式就可以了--把start转换成"yyyy/M/d"
2.new SimpleDateFormat("yyyy/M/d")中的"yyyy/M/d"换成start格式的。

81,092

社区成员

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

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