我在Android中遇到DATABASE问题,因为我的DATABASE已经过了2个月之后,我不能用查询做出这样的事情:
public LiveTvProgram currentPlayedProgram(int channelID) {
LiveTvProgram program = new LiveTvProgram();
long currentTime = System.currentTimeMillis();
String selectQuery = " SELECT * FROM " + TABLE_PROGRAMS + " WHERE " +
TvContract.Programs.COLUMN_START_TIME_UTC_MILLIS + " < " + currentTime +
" AND " + TvContract.Programs.COLUMN_END_TIME_UTC_MILLIS + " > " + currentTime + " AND "
+ TvContract.Programs.COLUMN_CHANNEL_ID + " = " + channelID;
Cursor cursor = myDataBase.rawQuery(selectQuery, null);
if(cursor != null && cursor.moveToFirst()){
program = LiveTvProgram.fromCursor(timeDifference, cursor);
cursor.close();
}
return program;
}
所以,当我这样做的时候,我刚刚在今天00:00获得了记录,而且就像是这样。它不是必须这样做,但我想问你,是否有可能从数据库中获取时间并做到这一点?
答案 0 :(得分:0)
是的,但您必须以适当的格式存储。
contentValues=null;
contentValues=new ContentValues();
cal=null;
cal=Calendar.getInstance();
currentDay=0;
currentDay=cal.get(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, currentDay+Pl+1);
contentValues.put("callfromdate",cal.getTime().toString());
contentValues.put("type","Dll");
contentValues.put("days",String.valueOf(Dl));
cal=null;
cal=Calendar.getInstance();
currentDay=0;
currentDay=cal.get(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, currentDay+Pl+Dl);
contentValues.put("calltodate",cal.getTime().toString());