2016-06-28 49 views
3

我在我的數據庫中將日期保存爲時間戳格式。我希望檢索特定日期的記錄(例如僅限今天的記錄)。如何格式化我的表格中存儲的格式化日期?以下是我目前的代碼:在查詢中將長日期轉換爲日期

public static long getTodayRecord(Context context, String recordId) { 
    long timeSpan= System.currentTimeMillis(); 
    String currentDay = DateTimeUtil.getDisplayShortDate(currentTimespan); 

    String dateString= DateFormat.format("MM/dd/yyyy", new Date(currentTimespan)).toString(); 

    String selection = "COLUMN_RECORD_ID" + " = ? AND date(" + "COLUMN_RECORD_DATE" + ") = ?"; 

    String[] selectionArg= {recordId, dateString}; 
    return DbUtil.count(context, "RECORD_TABLE, selection, selectionArgs); 
} 

任何意見是非常感謝。

回答

1
Date date=new Date(val); 
SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy"); 
String dateText = df2.format(date); 

如果你的日期是不是在長格式則必須轉換串地龍

long val = Long.parseLong(dateCreated);