Android 未处理的异常类型 ParseException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11665195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:24:28 来源:igfitidea点击:
unhandled exception type ParseException
提问by Tasos Moustakas
I'm using this part of code in my app :
我在我的应用程序中使用这部分代码:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
Date qdate = new GregorianCalendar(0,0,0).getTime();
try {
qdate = sdf.parse(dt);
} catch (ParseException e) {
e.printStackTrace();
}
but Eclipse throws an error saying :
但 Eclipse 抛出一个错误说:
Unhandled exception type ParseException
未处理的异常类型 ParseException
What is the problem here? Do u need me to post the whole code ? Thnx in advance !
这里有什么问题?你需要我发布整个代码吗?提前谢谢!
回答by Nirali
See below code
看下面的代码
String date = "Sat, 23 Jun 2012 00:00:00 +0000";
try {
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy");
date = df2.format(date));
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
回答by Nehru
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("DD-MM-YYYY");
String Currentdatestr = df.format(c.getTime());
//get current date in String
Date date = df.parse(Currentdatestr);
//String to parse Date Format