java.text.ParseException:无法解析的日期:"" (在偏移量0) [英] java.text.ParseException: Unparseable date: "" (at offset 0)
本文介绍了java.text.ParseException:无法解析的日期:"" (在偏移量0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读过很多回答这个问题,但没有答案解决我的问题。
I've read many answers to this problem but no answer solves my problem
我试图解析字符串:
2013-10-07T23:21:00 + 01:00
要一个Date对象,将SimpleDateFormat的:
to a Date object with the simpledateformat :
YYYY-MM-dd'T'HH:MM:ssZZZZZ
但它一直产生错误:
java.text.ParseException:无法解析的日期:(在偏移量0)
java.text.ParseException: Unparseable date: "" (at offset 0)
注:我在Android上尝试此,我是个初学者
Note: I am trying this on Android, I'm a beginner.
推荐答案
尝试使用以下code
Try with following code
public static Calendar parseDate(String dateTimeStr)
throws ParseException {
Calendar calendar = GregorianCalendar.getInstance();
String s = dateTimeStr.replace("Z", "+00:00");
try {
s = s.substring(0, 22) + s.substring(23);
} catch (IndexOutOfBoundsException e) {
throw new ParseException("Invalid length", 0);
}
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(s);
calendar.setTime(date);
return calendar;
}
这篇关于java.text.ParseException:无法解析的日期:"" (在偏移量0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文