医院废弃物信息化管理平台
“mitao”
2026-04-21 2f18b3a28054c3917010f95ba84f7425280a2622
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cn.besteam.common.util;
 
import java.util.Date;
 
public class CalculateCatUtil {
 
    //计算猫咪年龄
    public static String calculateAge(Date birthday) {
 
        if (birthday == null) {
            return "";
        }
        // Date birthday = DateUtil.parse("2020-03-31 12:11:22");
        int diffDays = (int) ((System.currentTimeMillis() - birthday.getTime()) / 1000 / 60 / 60 / 24);
        StringBuilder sb = new StringBuilder();
        if (diffDays == 0) {
            sb.append("1天");
            return sb.toString();
        }
        int year = diffDays / 365;
        int month = diffDays % 365 / 30;
        int day = diffDays % 365 % 30;
        if (year > 0) {
            sb.append(year).append("岁");
        }
        if (month > 0) {
            sb.append(month).append("个月");
        }
        if (day > 0) {
            sb.append(day).append("天");
        }
        return sb.toString();
    }
 
}