我试图用4.2.2上的Android构建解析日期并在2.2的模拟器上运行,它抛出异常。请帮忙!!这是我的代码
String date = "Mon Apr 08 00:00:00 IST 2013";
DateFormat parserSDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.getDefault());
parserSDF.setTimeZone(TimeZone.getTimeZone("IST"));
Calendar calendarEvent = Calendar.getInstance();
Date dateStr = null;
try {
dateStr = parserSDF.parse(date);
calendarEvent.setTime(dateStr);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("d>>"+calendarEvent.getTime());
04-17 13:01:42.658: W/System.err(1088): java.text.ParseException: Unparseable date: Mon Apr 08 00:00:00 IST 2013
04-17 13:01:42.667: W/System.err(1088): at java.text.DateFormat.parse(DateFormat.java:645)
04-17 13:01:42.667: W/System.err(1088): at com.example.datetest.MainActivity.onCreate(MainActivity.java:26)
04-17 13:01:42.667: W/System.err(1088): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-17 13:01:42.667: W/System.err(1088): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-17 13:01:42.667: W/System.err(1088): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-17 13:01:42.667: W/System.err(1088): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-17 13:01:42.667: W/System.err(1088): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-17 13:01:42.667: W/System.err(1088): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 13:01:42.667: W/System.err(1088): at android.os.Looper.loop(Looper.java:123)
04-17 13:01:42.667: W/System.err(1088): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-17 13:01:42.667: W/System.err(1088): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 13:01:42.678: W/System.err(1088): at java.lang.reflect.Method.invoke(Method.java:521)
04-17 13:01:42.678: W/System.err(1088): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-17 13:01:42.678: W/System.err(1088): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-17 13:01:42.678: W/System.err(1088): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
我认为你的格式应该是这样的:
"EEE MMM dd HH:mm:ss z yyyy"
因为您的时区不是全文。