我在表格中使用SQlite创建了日期字段。现在,当我尝试对这些日期进行排序时,我显示了错误的答案。我使用了一种“1-1月-2001”的格式来存储日期。如何按日期降序检索。我的价值观如下:
2013年6月24日
2013年6月26日
2012年6月13日
2013年6月13日
2013年6月9日
在进阶时谢谢。
发布于 2013-05-22 18:55:03
请参阅以下链接,sqlite没有date数据类型,因此您无法像在其他db中那样直接处理日期。
http://www.sqlite.org/datatype3.html
发布于 2013-05-22 18:59:32
不能通过Java包装器"ContentValues“使用datetime函数。
您可以使用:
SQL,以便您可以输入原始SQLiteDatabase.execSQL查询。
mDb.execSQL("INSERT INTO "+DATABASE_TABLE+" VALUES (null, datetime()) ");或java date time功能:
// set the format to sql date time
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
ContentValues initialValues = new ContentValues();
initialValues.put("date_created", dateFormat.format(date));
long rowId = mDb.insert(DATABASE_TABLE, null, initialValues);谢谢。
https://stackoverflow.com/questions/16689868
复制相似问题