【问题标题】:Convert long to date in query在查询中将 long 转换为 date
【发布时间】:2016-06-28 03:54:59
【问题描述】:

我已将我的日期以时间戳格式保存在我的数据库中。我希望检索特定日期的记录(例如仅今天的记录)。如何格式化存储在我的表中格式化为 long 的日期?以下是我当前的代码:

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);
}

非常感谢任何建议。

【问题讨论】:

    标签: android sqlite date compare


    【解决方案1】:
     Date date=new Date(val);
     SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy");
     String dateText = df2.format(date);
    

    如果您的日期不是长格式,则必须将字符串转换为长格式

    long val = Long.parseLong(dateCreated);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 2013-07-26
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多