首页 文章

无法解析的日期:Android中的“”(在偏移0处)

提问于
浏览
-2

我正在尝试解析字符串日期到日期,但得到java.text.ParseException的错误:无法解析的日期:“”(在偏移0处) . 这是转换date.Exception的方法发生在这一行 Date date = 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)

谢谢 .

1 回答

  • 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)
    

    ...这意味着您正在尝试将空字符串解析为日期 .

相关问题