java中日期格式的转换,String类型的如:03/Jun/2013这种格式的,怎样转换成yyyy-mm-dd格式的?

java中日期格式的转换,String类型的如:03/Jun/2013这种格式的,怎样转换成yyyy-mm-dd格式的?
数据库中读取一个VARCHAR类型的字段,如03/Jun/2013:00:00:05,在java中截取年月日为03/Jun/2013,但是页面根据这个日期进行搜索,页面上是日期控件,输入的格式是yyyy-mm-dd,匹配不上。有什么解决方法吗?
把所有笑或雹的格式都统一为yyyy-mm-dd。你的数据库类型是碰帆varchar把存入的字符串格式化一下不就OK?
java可以把各种格式的日期进行转化团搭。你看看SimpleDateFormat这个应该能找到解决办法。
从数据库获取的Date类型通过SimpleDateFormat来转换
一个比较笨的办法:

if(data != null ){
String year = data.substring(7, 11);
String month = data.substring(3, 6);
String date = data.substring(0,2);
if(month.equals("Jan")){
data = year + "-" + "01" + "-" + date;
}
if(month.equals("Feb")){
data = year + "-" + "02" + "-" + date;
}
if(month.equals("Mar"掘空)){
data = year + "-" + "03" + "-" + date;
}
if(month.equals("Apr")){
data = year + "-" + "04"纯轮 + "-" + date;
}
if(month.equals("May")){
data = year + "-" + "05" + "-" + date;
}
if(month.equals("Jun")){
data = year + "-" + "06" + "-" + date;
}
if(month.equals("Jul")){
data = year + "做散信-" + "07" + "-" + date;
}
if(month.equals("Aug")){
data = year + "-" + "08" + "-" + date;
}
if(month.equals("Sep")){
data = year + "-" + "09" + "-" + date;
}
if(month.equals("Oct")){
data = year + "-" + "10" + "-" + date;
}
if(month.equals("Nov")){
data = year + "-" + "11" + "-" + date;
}
if(month.equals("Dec")){
data = year + "-" + "12" + "-" + date;
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(data);
← 上一篇: 下一篇: →