当前位置:网站首页>The database records are read through the system time under the Android system, causing the problem of incomplete Reading Records!

The database records are read through the system time under the Android system, causing the problem of incomplete Reading Records!

2022-06-25 15:59:00 Favorite grapes

Android Under the system, read the database records through the system time , The reading record is incomplete !

demand

There are some records stored in the database , Time stamped . I need to read the data of the day ( according to Android Read the time of the plate )

So we have the following code :

Calendar instance = Calendar.getInstance();
instance.set(Calendar.SECOND, 0);
instance.set(Calendar.HOUR, 0);
instance.set(Calendar.MINUTE, 0);
instance.set(Calendar.MILLISECOND, 0);
long startTime = instance.getTimeInMillis();

instance.set(Calendar.SECOND, 59);
instance.set(Calendar.HOUR, 23);
instance.set(Calendar.MINUTE, 59);
long endTime = instance.getTimeInMillis();
session.queryBuilder(XXX.class)
.//  Here are N Many other conditions 
.where(XXXDao.Properties.Time.between(startTime, endTime))
.list();

result :
No problem running on my tablet , Running on most tablets is no problem .

Problem finding

There is a tablet in the test hand , One problem I found was , The record clearly shows the data of the day , But I just can't find it .

Problem solving process

First of all, I suspect that the database did not retrieve the data , So get rid of the other conditions , Start checking the database , It turns out that the data .

So the start judgment is that there is a problem with my start time and end time .

So the breakpoint is , Look at the data in the database , What is the difference between my start time and my end time .

Results found , The start time is greater than the timestamp of all data .

therefore , I guess there is a mistake in the above time calculation , Check the time setting code , Found out

instance.set(Calendar.HOUR, 0);

It's used here Calendar.HOUR, Suddenly think of , There seems to be another one Calendar.HOUR_OF_DAY.

So it was changed to Calendar.HOUR_OF_DAY.

The test again , And calculate the timestamp , Found it right , The records are also read out ~~

原网站

版权声明
本文为[Favorite grapes]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190538057152.html