【发布时间】:2013-10-14 19:19:06
【问题描述】:
在我的 android 应用程序中,我使用 STRFTIME 函数通过比较不同的日期字符串从 SQLite 获取数据。
我将 Promotion StartDate 和 EndDate 分别设置为 2013-10-07 和 2013-12-31。当前日期时间在StartDate 和EndDate 之间时存在促销。
以下是有效 strftime() 替换的完整列表:
%d day of month: 00
%f fractional seconds: SS.SSS
%H hour: 00-24
%j day of year: 001-366
%J Julian day number
%m month: 01-12
%M minute: 00-59
%s seconds since 1970-01-01
%S seconds: 00-59
%w day of week 0-6 with Sunday==0
%W week of year: 00-53
%Y year: 0000-9999=
我使用以下查询来检索数据。
Select * From Sal_Promotion p, Sal_Promotion_CustomerTypeAndProduct pd
Where p.Sal_PromotionID = d.Sal_PromotionID and
strftime('%s','now') >= strftime('%s',Sal_StartDate) and
strftime('%s','now') = strftime('%s',Sal_EndDate) and
Sal_CustomerTypeID = customerTypeID and
p.Sal_PromotionID = promoID;
当我在 2013 年 10 月 7 日早上 7 点测试我的应用程序时,我得到以下输出。
输出:
开始日期:2013-10-07 00:00:00(值:1381104000)
结束日期:2013-12-31 00:00:00(值:1388448000)
CurrentDateTime:2013-10-07 07:00:00(值:1381100400)
CurrentDateTime 值应介于 StartDate 和 EndDate 之间。但是为什么值是错误的?当前 DateTime 比 StartDate 晚 3600 秒(1 小时)。
我现在的城市是新加坡 (GMT+8:00)。是不是时差的原因?
谁能指出问题出在哪里?
【问题讨论】:
标签: java android sql datetime gmt