Commit 7eb43bdd72099a52c8d280124002f0cb37682c00
1 parent
4e3c201099
Exists in
master
and in
8 other branches
儿童月龄计算
Showing 1 changed file with 21 additions and 15 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java
View file @
7eb43bd
... | ... | @@ -379,7 +379,7 @@ |
379 | 379 | int day = daysBetween(birth,checkDate); |
380 | 380 | return day+"天"; |
381 | 381 | } |
382 | - | |
382 | + rightNow = Calendar.getInstance(); | |
383 | 383 | rightNow.setTime(checkDate); |
384 | 384 | rightNow.add(Calendar.MONTH,1); |
385 | 385 | rightNow.add(Calendar.YEAR,-1); |
386 | 386 | |
387 | 387 | |
... | ... | @@ -390,16 +390,21 @@ |
390 | 390 | |
391 | 391 | |
392 | 392 | Calendar yearNow = Calendar.getInstance(); |
393 | - yearNow.setTime(checkDate); | |
394 | - yearNow.add(Calendar.MONTH,-month); | |
393 | + yearNow.setTime(birth); | |
394 | + yearNow.add(Calendar.MONTH,month); | |
395 | 395 | |
396 | - int day = daysBetween(birth,yearNow.getTime()); | |
396 | + int day = daysBetween(yearNow.getTime(),checkDate); | |
397 | 397 | String dstr = ""; |
398 | 398 | if (day != 0) |
399 | 399 | { |
400 | 400 | dstr=day+"天"; |
401 | 401 | } |
402 | - return month+"月龄"+dstr; | |
402 | + String ms = ""; | |
403 | + if (month != 0) | |
404 | + { | |
405 | + ms = month+"月龄"; | |
406 | + } | |
407 | + return ms+dstr; | |
403 | 408 | } |
404 | 409 | int year = getYearSpace(birth, checkDate); |
405 | 410 | rightNow.setTime(checkDate); |
406 | 411 | |
... | ... | @@ -554,9 +559,10 @@ |
554 | 559 | System.out.println(new DateTime().minusDays(77));*/ |
555 | 560 | // System.out.println(getDaySeconds()); |
556 | 561 | |
557 | -// int s = getBabyAgeMonth(parseYMD("2016-05-26"), new Date()); | |
562 | + String s = getBabyMonthAge(parseYMD("2016-06-26"), new Date()); | |
563 | + System.out.println(s); | |
558 | 564 | // SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd "); |
559 | - System.out.println(getBabyAgeMonth(parseYMD("2016-05-23"), new Date())); | |
565 | +// System.out.println(getBabyAgeMonth(parseYMD("2016-05-23"), new Date())); | |
560 | 566 | // System.out.println(DateUtil.getyyyy_MM_dd_hms(DateUtil.addDay(new Date(),-108))); |
561 | 567 | // System.out.println(DateUtil.getyyyy_MM_dd_hms(DateUtil.addDay(new Date(), -146))); |
562 | 568 | // System.out.print(1457688652-23341); |
... | ... | @@ -572,14 +578,14 @@ |
572 | 578 | // Date startDate = DateUtil.addDay(d, -2); |
573 | 579 | // System.out.println(dd.format(startDate)); |
574 | 580 | |
575 | - Date sendDate = dd.parse("02"); | |
576 | - String md = DateUtil.getMMdd(new Date()); | |
577 | - String str = md +"-"+DateUtil.getDD(sendDate); | |
578 | - Date d = DateUtil.parseYMD(str); | |
579 | - | |
580 | - Date actualSendDate = DateUtil.addDay(d, -2); | |
581 | - String sendDateStr = DateUtil.getDD(actualSendDate); | |
582 | - System.out.println(sendDateStr); | |
581 | +// Date sendDate = dd.parse("02"); | |
582 | +// String md = DateUtil.getMMdd(new Date()); | |
583 | +// String str = md +"-"+DateUtil.getDD(sendDate); | |
584 | +// Date d = DateUtil.parseYMD(str); | |
585 | +// | |
586 | +// Date actualSendDate = DateUtil.addDay(d, -2); | |
587 | +// String sendDateStr = DateUtil.getDD(actualSendDate); | |
588 | +// System.out.println(sendDateStr); | |
583 | 589 | } catch (Exception e) |
584 | 590 | { |
585 | 591 |