我的日期字符串是“2016 年 10 月 17 日 12:17PM” 我的日期解析方法是:
public static String formatDate(String dateString) {
String stringDate = "";
try {
//Mar 11 2016 2:21PM
if (dateString != null) {
SimpleDateFormat dt = new SimpleDateFormat("MMM dd yyyy hh:mma");
Date date = dt.parse(dateString);
// *** same for the format String below
SimpleDateFormat dt1 = new SimpleDateFormat("EEE , hh:mm a");
stringDate = dt1.format(date);
}
return stringDate;
} catch (ParseException parseException) {
Log.e("date format", "" + parseException.getMessage());
}
return stringDate;
}
它在英语语言中运行良好,但是当我将应用程序语言更改为印地语或任何其他语言时,我遇到了异常。
java.text.ParseException: Unparseable date: "Oct 17 2016 12:17PM" (at offset 0)
我做什么?
最佳答案
您需要设置语言环境英语
SimpleDateFormat dt = new SimpleDateFormat("MMM dd yyyy hh:mma", Locale.ENGLISH);
关于java - java java.text.ParseException 中的日期解析异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40080436/