我从 db 获取 UTC 日期。并从当前的 UTC 日期时间中减去它。我想有差异。在几分钟内。有些东西不太对劲。
Date currenttimedate = DateTime.UTCNow();
String lastsynctime = c.getString(c.getColumnIndex(columnname)).toString();
Date lastruntimedate = DateTime.StringDateToDate(lastsynctime, "MM/dd/yyyy HH:mm:ss");
long diffInMs = (currenttimedate. getTime() - lastruntimedate.getTime());
// convert it to Minutes
long diffInMins = TimeUnit.MILLISECONDS.toMinutes(diffInMs);
// return time in minutes
response = (int)(diffInMins);
它返回大约 720 分钟。预期答案不能超过 5。因为数据每 5 分钟同步一次。