String转Date

[复制链接]
查看11 | 回复2 | 2007-10-20 08:38:44 | 显示全部楼层 |阅读模式
怎样将String:20080407,转成Date:2008-04-07
现在只能将String:2008-04-07 转成Date:2008-04-07

public static Date convertDate(String adateStrteStr, String format) {
java.util.Date date = null;
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
date = simpleDateFormat.parse(adateStrteStr);
} catch (Exception ex) {
LogHome.getLog().error("", ex);
}
return date;
}
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
format="yyyyMMdd" 就可以了!
回复

使用道具 举报

千问 | 2007-10-20 08:38:44 | 显示全部楼层
SimpleDateFormat formatter = new SimpleDateFormat(format);//format格式:"yyyy-MM-dd"
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(adateStrteStr, pos);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行