我創建的應用程序中的鳴叫的顯示列表我要顯示的時間像幾秒鐘前,1分鐘前,5M前,前1h ......昨天,最後的日期轉換日期爲字符串,如Twitter
我堅持了分秒幾秒鐘
public static String getTimeString(Date fromdate) {
long then;
then = fromdate.getTime();
Date date = new Date(then);
StringBuffer dateStr = new StringBuffer();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
Calendar now = Calendar.getInstance();
int days = daysBetween(calendar.getTime(), now.getTime());
int minutes = hoursBetween(calendar.getTime(), now.getTime());
int hours = minutes/60;
if (days == 0) {
int second = minuteBetween(calendar.getTime(), now.getTime());
if (minutes > 60) {
} else
if (hours > 24 && days <= 7) {
dateStr.append(days).append("d");
} else {
dateStr.append(twtimeformat.format(date));
}
return dateStr.toString();
}
public static int minuteBetween(Date d1, Date d2) {
return (int) ((d2.getTime() - d1.getTime())/DateUtils.SECOND_IN_MILLIS);
}
public static int hoursBetween(Date d1, Date d2) {
return (int) ((d2.getTime() - d1.getTime())/DateUtils.MINUTE_IN_MILLIS);
}
public static int daysBetween(Date d1, Date d2) {
return (int) ((d2.getTime() - d1.getTime())/DateUtils.DAY_IN_MILLIS);
}
謝謝@sishin – MilapTank
你能幫助我的花葯同類問題? http://pastie.org/private/tjontopamvrngykrlv2dgg看到鏈接 – MilapTank
好你需要那裏? – Sishin