私聊改造:用户卡片UI调整

This commit is contained in:
huangjian
2023-02-07 16:17:16 +08:00
parent 3b8796c378
commit f3a4af4582
9 changed files with 130 additions and 21 deletions

View File

@@ -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;
}
}