Я получаю дату из sqlite в этом формате = strSqliteDate: = 2015-10-07 12:59:49 PM. Я хочу, чтобы конвертировать SQLite datetime (strSqliteDate) в эту дату (2015-10-07) только. Я пытаюсь проанализировать дату в классе MyDbHelper, который расширяет SQLiteOpenHelper.Android: конвертировать SQLite только в дате
Вот мой код
public List<All_Post> getAllDescriptions()
{
List<All_Post> allPostDescList = new ArrayList<All_Post>();
String selectQuery = "select * from " + Table_AllPost_Table + " ORDER BY ActionDate DESC ";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do
{
All_Post allPostDesc = new All_Post();
allPostDesc.setID(cursor.getInt(cursor.getColumnIndex("ALL_ACT_ID")));
allPostDesc.setStrActivityId(cursor.getString(cursor.getColumnIndex("ActivityId")));
allPostDesc.setStrRemark(cursor.getString(cursor.getColumnIndex("Remark")));
allPostDesc.setStringInspectorname(cursor.getString(cursor.getColumnIndex("inspectorName")));
allPostDesc.setStrNotationNo(cursor.getString(cursor.getColumnIndex("HashTag")));
allPostDesc.setStrShortName(cursor.getString(cursor.getColumnIndex("Type_ShortRGN")));
String strSqliteDate = cursor.getString(cursor.getColumnIndex("ActionDate"));
Log.e("strSqliteDate "," = " + strSqliteDate);
Format formatter = new SimpleDateFormat("yyyy-MM-dd");
String formattedCode = formatter.format("supply your date-time here");
Log.e(" newDate "," = "+formattedCode);
allPostDesc.setActiondate(formattedCode);
allPostDescList.add(allPostDesc);
} while (cursor.moveToNext());
}
db.close();
return allPostDescList;
}
При запуске приложение разбился и получать ошибки, как IllegalArgumentException Вот мой журнал ошибок кот
10-08 11:52:29.061 9567-9567/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tazeen.classnkk/com.example.tazeen.classnkk.AllPosts_Page}: java.lang.IllegalArgumentException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
at android.app.ActivityThread.access$600(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException
at java.text.DateFormat.format(DateFormat.java:365)
at java.text.Format.format(Format.java:93)
at com.example.DBsqlite.MyDbHelper.getAllDescriptions(MyDbHelper.java:387)
at com.example.tazeen.classnkk.AllPosts_Page.onCreate(AllPosts_Page.java:177)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
at android.app.ActivityThread.access$600(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Как преобразовать строку в даты only.thanks в оценка
http://stackoverflow.com/a/18733587 – Sree
Использовать простой формат даты –
'String formattedCode = formatter.format (« укажите дату и время здесь »);' Появляется ** очевидно **, что '' поставка ваше время-дата здесь "' не является допустимой строкой даты, и она ** не может быть обработана **. –