| | |
| | | */ |
| | | public static Date parse(String date, String pattern) { |
| | | try { |
| | | if(Objects.nonNull(date)) { |
| | | if (Objects.nonNull(date)) { |
| | | return DateUtils.parseDate(date, pattern); |
| | | } |
| | | } catch (ParseException e) { |
| | |
| | | return dateStr; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 得到n天之后的日期 |
| | | */ |
| | | public static String getAfterDayDate2(Date date, String days) { |
| | | int daysInt = Integer.parseInt(days); |
| | | |
| | | Calendar canlendar = Calendar.getInstance(); // java.util包 |
| | | canlendar.setTime(date); |
| | | canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动 |
| | | Date afterDate = canlendar.getTime(); |
| | | |
| | | SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String dateStr = sdfd.format(afterDate); |
| | | |
| | | return dateStr; |
| | | } |
| | | |
| | | /** |
| | | * 得到n天之后是周几 |
| | | */ |
| | |
| | | Calendar cal = Calendar.getInstance(); |
| | | return cal; |
| | | } |
| | | |
| | | /** |
| | | * 毫秒转日期时间 |
| | | * |
| | |
| | | |
| | | /** |
| | | * 计算年龄 |
| | | * |
| | | * @param birthDate |
| | | * @return |
| | | */ |
| | |
| | | // 粗计算年龄 |
| | | int age = yearNow - yearBirth; |
| | | // 当前月份小于出生月份年龄减一 |
| | | if (monthNow < monthBirth) { age--; } |
| | | if (monthNow < monthBirth) { |
| | | age--; |
| | | } |
| | | // 当前月份等于出生月份,日小于生日年龄减一 |
| | | else if (monthNow == monthBirth && dayNow < dayBirth) { age--; } |
| | | else if (monthNow == monthBirth && dayNow < dayBirth) { |
| | | age--; |
| | | } |
| | | // 返回年龄值 |
| | | return age; |
| | | } |