【发布时间】:2014-07-24 17:02:00
【问题描述】:
我想将日期解析为所需的格式,但我每次都收到异常。 我知道这很容易实现,但我遇到了一些不知道具体在哪里的问题。:
Exception: java.text.ParseException: Unparseable date: "2014-06-04" (at offset 5)
以下是我的代码:
private String getconvertdate(String date) {
DateFormat inputFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss",Locale.ENGLISH);
inputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
DateFormat outputFormat = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH);
Date parsed = null;
try {
parsed = inputFormat.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String outputText = outputFormat.format(parsed);
return outputText;
}
方法输入:2014-06-04
预计产出:2014 年 6 月 6 日
我关注了一些 Ref。来自 Stackoverflow.com,但问题仍然存在。 请帮忙。
【问题讨论】:
标签: java android android-date