2016-08-01 65 views
0

我有android系統數據庫的問題,因爲我的數據庫是有像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,和everthing是這樣的。它不需要這樣做,但我想問你,是否有可能從數據庫中獲取時間並執行此操作?

+0

您是否試圖獲取數據庫的日期時間並將其返回給應用程序? – Takarii

+0

我不能調用類似myDatabase.getTime或getDate – Genehme

+0

來獲得當前的日期時間,你會想'DATETIME('now')' – Takarii

回答

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()); 
+0

好吧,但如何比較這與數據庫呢? – Genehme

+0

這是一個圓頂首先你必須在數據庫中存儲時間和日期然後我們比較 –

相關問題