From b27b0c36531dd6203174c647ef1be77c6aecf786 Mon Sep 17 00:00:00 2001 From: jiangjiazhi Date: Tue, 27 Sep 2016 12:10:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E7=97=85=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lyms/platform/common/utils/DateUtil.java | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java index 6292b73..94c2d7f 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java @@ -47,13 +47,41 @@ public class DateUtil { } public static Integer getAge(Date birth) { - if (birth == null) { - return null; + + java.util.Calendar calendar= Calendar.getInstance(); + Date date=new Date(); + calendar.setTime(date); + + Calendar c1 = Calendar.getInstance(); + Calendar c2 = Calendar.getInstance(); + c1.setTime(date); + c2.setTime(birth); + int year1 = c1.get(Calendar.YEAR); + int year2 = c2.get(Calendar.YEAR); + + int mouth1 = c1.get(Calendar.MONTH); + int mouth2 = c2.get(Calendar.MONTH); + int i=0; + if(mouth1-mouth2>=0){ + int days1 = c1.get(Calendar.DAY_OF_MONTH); + int days2 = c2.get(Calendar.DAY_OF_MONTH); + if(days1days2){ + } + }else if(mouth1-mouth2<0){ + i=i-1; } - Date now = new Date(); - long m = now.getTime() - birth.getTime(); - Long age = m / 31536000000L; - return age.intValue(); + + +// if (birth == null) { +// return null; +// } +// Date now = new Date(); +// long m = now.getTime() - birth.getTime(); +// Long age = m / 31536000000L; +// return age.intValue(); + return (Math.abs(year1 - year2)+i); } public static Integer getAge(Date birth,Date fmDate) { if (birth == null) { -- 1.8.3.1