【发布时间】:2015-08-14 04:16:23
【问题描述】:
如何将日期(Mon Jan 12 00:00:00 IST 2015) 转换为MM.dd.yyyy 或dd.MM.yyyy 格式?
我尝试使用以下方法
String dateStr = "Mon Jan 12 00:00:00 IST 2015";
DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
System.out.println(formatter.format(dateStr));
但是得到了,
Exception in thread "main" java.lang.IllegalArgumentException:
Cannot format given Object as a Date
【问题讨论】:
-
首先你必须将字符串解析为日期,然后你可以格式化它