0

我想将“现在”长/日期值减去“最后通知时间”长/数据值与表示发出新通知之前的分钟间隔的整数值进行比较。

我知道我不能简单地这样做:

bool bItIsTime = (iMinutesBetweenNotifications < (lLastNotificationTime - lRightNow));

...但是有什么办法呢。如果“现在”的值为 42.2468,那么此时 41.2468 会是​​昨天吗?IOW,1.00 == 1 天吗?(在这种情况下 0.1 == 144 分钟,0.01 == 14.4 分钟等)?

4

1 回答 1

1

如果您long从 Date 或 Calendar 对象中提取上次通知时间的值,该值通常是自 1970 年 1 月 1 日 GMT 以来的毫秒数。这也是您从中获得的相同单位System.currentTimeMillis()。您可以像这样进行测试:

long now = System.currentTimeMillis();
bool bItIsTime = iMinutesBetweenNotifications * 60000 // convert to milliseconds
    > now - lLastNotificationTime;
if (bItIsTime) {
    issueNotification();
    lLastNotificationTime = now;
}
于 2011-12-19T03:59:19.383 回答