在我的应用程序中,您使用 date/timePickers 设置日期/时间。
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date datahora;
datahora = (Date) formatter.parse(data);
我需要将我设置的时间与手机的实际时间进行比较。所以我试过这个:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date datahora;
String datatmp = formatter.format(new Date(0));
try {
datahora = (Date) formatter.parse(data);
if(datahora <= datatmp)
但我确实知道它错了,因为它说它无法检查date > string
但我不知道如何检查实际时间。
编辑
日志猫
10-08 20:14:07.453: E/AndroidRuntime(261): FATAL EXCEPTION: main
10-08 20:14:07.453: E/AndroidRuntime(261): java.lang.IllegalStateException: get field slot from row 0 col -1 failed
10-08 20:14:07.453: E/AndroidRuntime(261): at android.database.CursorWindow.getString_native(Native Method)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.database.CursorWindow.getString(CursorWindow.java:329)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
10-08 20:14:07.453: E/AndroidRuntime(261): at com.example.mensagem.Mensagenssalvas$1.onItemClick(Mensagenssalvas.java:59)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.widget.ListView.performItemClick(ListView.java:3382)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.os.Handler.handleCallback(Handler.java:587)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.os.Handler.dispatchMessage(Handler.java:92)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.os.Looper.loop(Looper.java:123)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-08 20:14:07.453: E/AndroidRuntime(261): at java.lang.reflect.Method.invokeNative(Native Method)
10-08 20:14:07.453: E/AndroidRuntime(261): at java.lang.reflect.Method.invoke(Method.java:521)
10-08 20:14:07.453: E/AndroidRuntime(261): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-08 20:14:07.453: E/AndroidRuntime(261): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-08 20:14:07.453: E/AndroidRuntime(261): at dalvik.system.NativeStart.main(Native Method)