在我的Android应用程序中,如果自上次导入至少X小时后才重新导入数据,检查当前时间距“last_updated”时间是否超过一个小时
我存储的LAST_UPDATED时间在我的SQLite数据库格式为: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;
}
}
你可以只保存在毫秒的时间。然后,你只需要计算差异,并以每小时毫秒数为单位来划分它 – Weeman 2012-07-18 00:32:52