作者:庾承泓_689 | 来源:互联网 | 2023-09-23 15:17
This question already has an answer here:
这个问题在这里已有答案:
- Java : how to add 10 mins in my Time 8 answers
Java:如何在我的Time 8答案中添加10分钟
- How can I read and parse a date and time in Android? 2 answers
如何在Android中阅读和解析日期和时间? 2个答案
I am calling an API and as per the guidelines calling it every time is inefficient as the data does not change that regularly. They recommend calling it once and then not polling until 10 minutes has passed.
我正在调用一个API,并且根据每次调用它的指南都是低效的,因为数据不会定期更改。他们建议调用一次,然后在10分钟后才进行轮询。
I am calling this from an Android app and so I want to store the current date plus 10 minutes. I do this like so:
我从一个Android应用程序调用它,所以我想存储当前日期加上10分钟。我是这样做的:
Date forecastRefreshDate = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(forecastRefreshDate);
cal.add(Calendar.MINUTE, 10);
editor.putString("ForecastRefreshDate", forecastRefreshDate.toString());
editor.apply();
So now when this code is run again it needs to check if the current time (new Date()) is > the value saved in the cache/app file.
所以现在再次运行此代码时,需要检查当前时间(new Date())是否>缓存/ app文件中保存的值。
How do I create a Date variable equal to the value stored in the cache as a String?
如何创建一个Date变量,该变量等于存储在缓存中的值为String?
5 个解决方案