【发布时间】:2012-06-21 06:33:33
【问题描述】:
我有一个类似于以下Mon Jun 18 00:00:00 IST 2012 的值,我想将其转换为18/06/2012
如何转换?
我试过这个方法
public String toDate(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date theDate = null;
//String in = date + "/" + month + "/" + year;
try {
theDate = dateFormat.parse(date.toString());
System.out.println("Date parsed = " + dateFormat.format(theDate));
} catch (ParseException e) {
e.printStackTrace();
}
return dateFormat.format(theDate);
}
但它会引发以下异常:
java.text.ParseException: Unparseable date: "Mon Jun 18 00:00:00 IST 2012"
【问题讨论】:
-
查看本页相关部分
-
@Kazekage Gaara 你现在可以看到我的编辑,让我们希望你是否知道答案。
-
同意托尼的观点,如果不让其他人回答,您可以尝试回答,而不是投票给好评。
-
How to parse a date?的可能重复
-
@SAR 我面临同样的问题,请帮助