有人可以推荐最佳方式转换字符串格式为“周六,2015年4月11日17:48:17 + 0430'在java中的日期?
我这样做:
String date="Sat, 11 Apr 2015 17:48:17 +0430";
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date startDate;
try {
startDate = df.parse(date);
String newDateString = df.format(startDate);
System.out.println(newDateString);
} catch (ParseException e) {
e.printStackTrace();
}
错误:
04-11 13:37:50.956 2186-2200/latest.sports.news W/System.err﹕ java.text.ParseException: Unparseable date: "Sat, 11 Apr 2015 17:48:17 +0430" (at offset 0)
04-11 13:37:50.956 2186-2200/latest.sports.news W/System.err﹕ at java.text.DateFormat.parse(DateFormat.java:626)
更新:
如何将Sat, 11 Apr 2015 17:48:17 +0430
转换为04/11/2015
答案 0 :(得分:0)
String date="Sat, 11 Apr 2015 17:48:17 +0430";
DateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
Date startDate;
try {
startDate = df.parse(date);
String newDateString = df.format(startDate);
System.out.println(newDateString);
} catch (ParseException e) {
e.printStackTrace();
}