Android 앱에서 마지막 가져 오기 후 X 시간 이상 지난 경우에만 데이터를 다시 가져오고 싶습니다.현재 시간이 "last_updated"시간에서 1 시간 이상인지 확인하십시오.
나는 형식으로 내 SQLite 데이터베이스에 LAST_UPDATED 시간을 저장하고 있습니다 : 2012/07/18 00:01:40
이 어떻게 그런 "그때부터 시간"또는 무언가를 얻을 수 있나요? 지금까지
내 코드 :
package com.sltrib.utilities;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class DateHelper
{
public static String now()
{
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String dateNow = formatter.format(currentDate.getTime());
//System.out.println("Now the date is :=> " + dateNow);
return dateNow;
}
public static int hoursAgo(String datetime)
{
//return the number of hours it's been since the given time
//int hours = ??
//return hours;
}
}
당신은 MS의 시간을 저장할 수 있습니다. 그런 다음 차이점을 계산하고 시간당 mmilliseconds 수로 나눠야합니다. – Weeman