【问题标题】:SQLITE next 24 hours dataSQLITE 未来 24 小时数据
【发布时间】:2015-05-09 09:34:08
【问题描述】:

我希望从我的桌子上选择接下来 24 小时的游戏:

String sql = "SELECT * FROM teamstable 
             WHERE ((teamdate >= datetime ('now'))
             AND (teamdate < datetime('now','+24 hours')))
             ORDER BY teamdate";

Cursor cursor = db.rawQuery(sql, null);

但结果很奇怪,因为我只有明天的比赛:

String teamDate48 = "2015-03-08 21:30";
.
.
String teamDate54 = "2015-03-08 13:00";

我也应该有今天的比赛:

String teamDate41 = "2015-03-07 20:30";
.
.
String teamDate47 = "2015-03-07 19:00";

如果相关,我也会在此操作中将日期格式化为当地时间:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

Date datex = null;
try 
{
    sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    datex = sdf.parse(tdate111);
    System.out.println(datex);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    sdf.setTimeZone(TimeZone.getDefault());

我的猜测是:问题是由我的手机 (GMT) 和存储的日期 (America/New_York) 之间的时区差异引起的。会不会是这个原因?

【问题讨论】:

  • 阅读documentation
  • @CL。你能更精确一点吗?我应该使用 'strftime' 而不是 datetime 还是需要在我的字符串中添加 ":SS"
  • @nate-barbettini 感谢伟大的改进,我必须学习更多的英语......哈哈

标签: android sqlite calendar timezone


【解决方案1】:

documentation 提到了日期/时间函数:

使用世界协调时间 (UTC)。

直接支持的唯一其他时区是操作系统报告的时区,但在您的情况下,它是相同的。

要在时区之间转换,请使用修饰符来添加/减去所需的小时数。

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    相关资源
    最近更新 更多