私聊改造:用户卡片UI调整
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.mango.core.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class CurrentTimeUtils {
|
||||
|
||||
private static long offsetTime;
|
||||
@@ -12,4 +15,33 @@ public class CurrentTimeUtils {
|
||||
public static long getCurrentTime() {
|
||||
return System.currentTimeMillis() - offsetTime;
|
||||
}
|
||||
|
||||
public static int getAgeFromTimestamp(long timestamp) {
|
||||
|
||||
Date birthDay = new Date(timestamp);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date(getCurrentTime()));
|
||||
int yearNow = cal.get(Calendar.YEAR);
|
||||
int monthNow = cal.get(Calendar.MONTH);
|
||||
int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
|
||||
cal.setTime(birthDay);
|
||||
|
||||
int yearBirth = cal.get(Calendar.YEAR);
|
||||
int monthBirth = cal.get(Calendar.MONTH);
|
||||
int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
int age = yearNow - yearBirth;
|
||||
|
||||
if (monthNow <= monthBirth) {
|
||||
if (monthNow == monthBirth) {
|
||||
if (dayOfMonthNow < dayOfMonthBirth)
|
||||
age--;
|
||||
} else {
|
||||
age--;
|
||||
}
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user