java中。如何将sDate='2010-02-12'转换为'2010年2月12日'

如题所述

第1个回答  2011-04-28
public static Date getFormatDate(String dateString, String dateType) {
try {
if (dateType.equals("yyyy-MM-dd")) {
return shortFormat.parse(dateString);
} else if (dateType.equals("yyyy-MM-dd HH:mm:ss")) {
return longFormat.parse(dateString);
} else {
return new java.text.SimpleDateFormat(dateType)
.parse(dateString);
}
} catch (ParseException ex) {
ex.printStackTrace();
}
return new Date();
}
然后 在转换成你想要的 类型
// 根据格式获取时间字符串
public static String getTiemModle(Date date, String modle) {
java.text.SimpleDateFormat sf = new SimpleDateFormat(modle);
return sf.format(date);
}
第2个回答  2011-04-28
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
/**
* 把一个字符串转换成Timestamp
*/
public static Timestamp getTime(String time){

try {
Date date = sdf.parse(time);
Timestamp timestamp =new Timestamp(date.getTime());
return timestamp;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

方法2:直接使用split拆解 形成String数组
然后拼接数组String result = array[0]+"年"+array[1]+"月"+array[2]+"日"本回答被提问者采纳
第3个回答  2011-04-29
System.out.println(new SimpleDateFormat("yyyy年MM月dd日").format(new Date(
System.currentTimeMillis())));

把上面的改成你需要的样子。
第4个回答  2011-04-28
public static String changeDate(){
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String strDate=sdf.format(date);

return strDate.split("-")[0]+"年"+strDate.split("-")[1]+"月"+strDate.split("-")[2]+"日";
}