我对 Android 非常陌生。我从以下格式的服务器获取字符串形式的日期
2012-08-17 00:00:00
我想将此字符串与当前日期进行比较,以查找年、月和日形式的日期之间的差异。
我尝试在下面的代码中玩它
Date currentDate = new Date(System.currentTimeMillis());
Log.v("@@@@@@@@@","Current Date: " + currentDate);
Date passDate = new SimpleDateFormat().parse(passDateString);
Log.v("@@@@@@@@@","Pass Date: " + passDate);
dateDifference = passDate.compareTo(currentDate);
但它返回以下异常
04-15 12:08:29.101: V/@@@@@@@@@(1161): Current Date: Sun Apr 15 12:08:29 GMT+01:00 2012
04-15 12:08:29.101: W/System.err(1161): java.text.ParseException: Unparseable date: 2012-08-17 00:00:00
04-15 12:08:29.111: W/System.err(1161): at java.text.DateFormat.parse(DateFormat.java:645)
04-15 12:08:29.111: W/System.err(1161): at org.apis.PassesListItemAdapter.getView(PassesListItemAdapter.java:77)
04-15 12:08:29.111: W/System.err(1161): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
04-15 12:08:29.111: W/System.err(1161): at android.widget.ListView.makeAndAddView(ListView.java:1727)
04-15 12:08:29.111: W/System.err(1161): at android.widget.ListView.fillDown(ListView.java:652)
04-15 12:08:29.111: W/System.err(1161): at android.widget.ListView.fillFromTop(ListView.java:709)
04-15 12:08:29.111: W/System.err(1161): at android.widget.ListView.layoutChildren(ListView.java:1580)
04-15 12:08:29.111: W/System.err(1161): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
04-15 12:08:29.111: W/System.err(1161): at android.view.View.layout(View.java:7034)
04-15 12:08:29.111: W/System.err(1161): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
04-15 12:08:29.111: W/System.err(1161): at android.view.View.layout(View.java:7034)
04-15 12:08:29.111: W/System.err(1161): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
04-15 12:08:29.111: W/System.err(1161): at android.view.View.layout(View.java:7034)
04-15 12:08:29.111: W/System.err(1161): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
04-15 12:08:29.111: W/System.err(1161): at android.view.View.layout(View.java:7034)
04-15 12:08:29.111: W/System.err(1161): at android.view.ViewRoot.performTraversals(ViewRoot.java:1049)
04-15 12:08:29.111: W/System.err(1161): at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
04-15 12:08:29.111: W/System.err(1161): at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 12:08:29.111: W/System.err(1161): at android.os.Looper.loop(Looper.java:144)
04-15 12:08:29.111: W/System.err(1161): at android.app.ActivityThread.main(ActivityThread.java:4937)
04-15 12:08:29.111: W/System.err(1161): at java.lang.reflect.Method.invokeNative(Native Method)
04-15 12:08:29.111: W/System.err(1161): at java.lang.reflect.Method.invoke(Method.java:521)
04-15 12:08:29.111: W/System.err(1161): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-15 12:08:29.111: W/System.err(1161): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-15 12:08:29.111: W/System.err(1161): at dalvik.system.NativeStart.main(Native Method)