0

我正在使用 Joda time android,当我尝试获取两个时间戳之间的差异时,值从 0 增加到 59,并且永远不会超过此值。

我正在使用https://github.com/dlew/joda-time-android

任何指针将不胜感激。

这就是我所拥有的

DateTime currentTime = new DateTime();
                Period difference = new Period(calculator.getLastTotalizerChangeTime(meterMeasurement.getFlowMeterId()), currentTime);
                Log.d("totaliserSenseCheck", "fcalculator.getLastTotalizerChangeTime() - " + calculator.getLastTotalizerChangeTime(meterMeasurement.getFlowMeterId())
                        + " currentTime - " + currentTime
                        + " difference - " + difference.getSeconds());

日志 fcalculator.getLastTotalizerChangeTime() 未更改,仅更改当前时间,但差异永远不会超过 59 并重置为 0

D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:03:42.730+01:00 difference - 2
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:03:47.335+01:00 difference - 7
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:03:51.113+01:00 difference - 11
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:04:00.793+01:00 difference - 20
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:04:40.369+01:00 difference - 0
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:04:51.574+01:00 difference - 11
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:05:08.914+01:00 difference - 28
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:05:36.840+01:00 difference - 56
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:05:39.070+01:00 difference - 59
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:05:44.526+01:00 difference - 4
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:09:09.579+01:00 difference - 29
D/totaliserSenseCheck: fcalculator.getLastTotalizerChangeTime() - 2019-09-12T16:03:40.002+01:00 currentTime - 2019-09-12T16:09:43.226+01:00 difference - 3
4

1 回答 1

2

该方法getSeconds()不返回秒数,它返回秒作为一个单独的字段,其中一个时间段已被分解为小时、分钟、秒等多个字段。因此,如果时间差为 10 小时、11 分钟和 40秒,getSeconds()只会给你 40 的一部分。

我之前没有使用过 Joda 时间,但我认为您想要的方法是toStandardSeconds().getSeconds().

于 2019-09-12T15:29:40.150 回答