如何使用orderby作为日期,以毫秒为单位

时间:2014-09-29 09:25:56

标签: android sqlite

我想让所有重新编码器按降序日期排序

我尝试了以下方法 MySQLiteHelper.COLUMN_DATE包含以毫秒为单位的日期字符串(如1411982657593)。但是,我仍然通过创建而不是选择日期来接收记录。我该怎么办?

public ArrayList<MyCelebration> getAllComments() {
        ArrayList<MyCelebration> myCelebrations = new ArrayList<MyCelebration>();
        String orderBy = "datetime("+MySQLiteHelper.COLUMN_DATE + ") DESC";
        Cursor cursor = database.query(
                MySQLiteHelper.TABLE_CELEBRATION, allColumns, null, null, null, null, orderBy
        );

        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            MyCelebration myCelebration = cursorToComment(cursor);
            myCelebrations.add(myCelebration);
            cursor.moveToNext();
        }
        // make sure to close the cursor
        cursor.close();
        return myCelebrations;
    }

1 个答案:

答案 0 :(得分:0)

正如评论所指出的那样,按日期订购原料:

String orderBy = MySQLiteHelper.COLUMN_DATE + " DESC";