LocalDate转换String类型日期,日、周、月、年
/*** 获取今天开始时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getTodayStartTime(){LocalDate localDate = LocalDate.now();return localDate + " 00:00:00";
}
/*** 获取今天结束时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getTodayEndTime(){LocalDate localDate = LocalDate.now();return localDate + " 23:59:59";
}
/*** 获取今月开始时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getThisMonthStartTime(){LocalDate localDate = LocalDate.now();return localDate.getYear() + "-" + localDate.getMonthValue() + "-01" + " 00:00:00";
}
/*** 获取本周开始时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getThisWeekStartTime(){SimpleDateFormat formater=new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");Calendar cal=new GregorianCalendar();cal.setFirstDayOfWeek(Calendar.MONDAY);cal.setTime(new Date());cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());return formater.format(new Date(cal.getTimeInMillis()/1000));
}
/*** 获取本周结束时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getThisWeekEndTime(){SimpleDateFormat formater=new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");Calendar cal=new GregorianCalendar();cal.setFirstDayOfWeek(Calendar.MONDAY);cal.setTime(new Date());cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek() + 6);return formater.format(new Date(cal.getTimeInMillis()/1000));
}
/*** 获取今月结束时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getThisMonthEndTime(){LocalDate localDate = LocalDate.now();return localDate.getYear() + "-" + localDate.getMonthValue() + "-" + localDate.lengthOfMonth() + " 23:59:59";
}
/*** 获取今年开始时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getThisYearStartTime(){LocalDate localDate = LocalDate.now();return localDate.getYear() + "-01" + "-01" + " 00:00:00";
}
/*** 获取今年结束时间* return 'yyyy-MM-dd hh:mm:ss'*/
public static String getThisYearEndTime(){LocalDate localDate = LocalDate.now();localDate.withMonth(12);return localDate.getYear() + "-" + localDate.getMonthValue() + "-" + localDate.lengthOfMonth() + " 23:59:59";
}