我正在尝试解析字符串日期到日期,但是得到java.text.ParseException的错误:无法解析日期:“”(在偏移0处)。这是转换date.Exception的方法在此行发生日期日期= simpleDateFormat.parse(dateString);
public static String convertDateStringFormat(String dateString, String originalDateFormat, String outputDateFormat){
String finalDate = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(originalDateFormat);
try {
Date date = simpleDateFormat.parse(dateString);
simpleDateFormat = new SimpleDateFormat(outputDateFormat);
finalDate = simpleDateFormat.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
return finalDate;
}
String newDateString = Constant.convertDateStringFormat(strActiondate , "MM/dd/yyyy hh:mm:ss a", "yyyy-MM-dd hh:mm:ss a");
Log.e("newDateString "," = " + newDateString );
转换了一些字符串日期,某些日期变为空并出现java.text.ParseException:Unparseable date:“”(偏移0处)。
这是我的日志cat错误
02-22 10:40:15.539 11336-11465/com.example.tazeen.classnkk E/newDateString﹕ = null
02-22 10:40:15.539 11336-11465/com.example.tazeen.classnkk E/newDateString﹕ = 2015-12-03 12:00:00 AM
02-22 10:40:15.540 11336-11465/com.example.tazeen.classnkk E/newDateString﹕ = 2015-12-09 12:00:00 AM
02-22 10:40:15.540 11336-11465/com.example.tazeen.classnkk E/newDateString﹕ = 2015-12-01 12:00:00 AM
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ java.text.ParseException: Unparseable date: "" (at offset 0)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at java.text.DateFormat.parse(DateFormat.java:579)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at com.example.AdapterClasses.Constant.convertDateStringFormat(Constant.java:49)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at com.example.tazeen.classnkk.CustomActionActivity.GetAllActivityList(CustomActionActivity.java:1572)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at com.example.tazeen.classnkk.CustomActionActivity$GetAllServicesDetails.doInBackground(CustomActionActivity.java:1229)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at com.example.tazeen.classnkk.CustomActionActivity$GetAllServicesDetails.doInBackground(CustomActionActivity.java:1216)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-22 10:40:15.541 11336-11465/com.example.tazeen.classnkk W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
感谢。
答案 0 :(得分:2)
异常的格式通常是
java.text.ParseException:
Unparseable date: "Mon Oct 20 00:00:00 GMT+06:30 2014" (at offset 0)
...将不可解决的日期作为异常消息的一部分,并且您正在获取......
java.text.ParseException:
Unparseable date: "" (at offset 0)
...这意味着您尝试将空字符串解析为日期。