| | |
| | | calendar.setTime(getDate()); |
| | | return calendar.get(Calendar.YEAR); |
| | | } |
| | | |
| | | public static String getDayStr(Date date) { |
| | | Calendar calendar = getCalendar(); |
| | | calendar.setTime(date);// 把当前时间赋给日历 |
| | |
| | | String dayStr = day < 10 ? "0" + day : day + ""; |
| | | return dayStr; |
| | | } |
| | | |
| | | /** |
| | | * 将字符串转成时间 |
| | | * @param str |
| | |
| | | public static Date localDateToDate(LocalDate localDate) { |
| | | return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); |
| | | } |
| | | |
| | | /** |
| | | * 日期加年 |
| | | * @param date |
| | | * @param year |
| | | * @return |
| | | */ |
| | | public static Date addYear(Date date, int year) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.add(Calendar.YEAR, year); |
| | | return calendar.getTime(); |
| | | } |
| | | } |