当前位置: 首页 > 工具软件 > xk-time > 使用案例 >

java调用日期的包_Java日期时间API系列27-----Jdk8中java.time包中的新的日期时间API类,使用xk-time工具类创建日历应用。...

阎建华
2023-12-01

packagecom.xkzhangsan.time.calendar;importjava.time.LocalDateTime;importjava.time.YearMonth;importjava.util.ArrayList;importjava.util.List;importjava.util.Map;importjava.util.concurrent.ConcurrentHashMap;importcom.xkzhangsan.time.calculator.DateTimeCalculatorUtil;importcom.xkzhangsan.time.formatter.DateTimeFormatterUtil;/*** 日历工具类

*

* @ClassName: CalendarUtil

* @Description: CalendarUtil

*@authorxkzhangsan

* @date 2020年03月18日*/

public classCalendarUtil {privateCalendarUtil() {

}/*** 生成指定年月的日历

*@paramyear

*@parammonth

*@return

*/

public static CalendarWrapper generateCalendar(int year, intmonth){

CalendarWrapper calendarWrapper= newCalendarWrapper();

Map dayMap = new ConcurrentHashMap();

List localDateTimeList =DateTimeCalculatorUtil.getLocalDateTimeList(YearMonth.of(year, month));if(localDateTimeList == null ||localDateTimeList.isEmpty()){returncalendarWrapper;

}

List dayWrapperList = new ArrayList<>();

localDateTimeList.stream().forEach(localDateTime->{

DayWrapper dayWrapper= newDayWrapper(localDateTime);

dayWrapperList.add(dayWrapper);

dayMap.put(DateTimeFormatterUtil.formatToDateStr(localDateTime), dayWrapper);

});

MonthWrapper monthWrapper= newMonthWrapper(month, dayWrapperList);

List monthWrapperList = new ArrayList<>();

monthWrapperList.add(monthWrapper);

YearWrapper yearWrapper= newYearWrapper(year, monthWrapperList);

List yearWrapperList = new ArrayList<>();

yearWrapperList.add(yearWrapper);

calendarWrapper= newCalendarWrapper(yearWrapperList, dayMap);returncalendarWrapper;

}/*** 生成指定年的日历

*@paramyear

*@return

*/

public static CalendarWrapper generateCalendar(intyear){

CalendarWrapper calendarWrapper= newCalendarWrapper();

Map dayMap = new ConcurrentHashMap();

List monthWrapperList = new ArrayList<>();for(int i=1; i<=12; i++){

List localDateTimeList =DateTimeCalculatorUtil.getLocalDateTimeList(YearMonth.of(year, i));if(localDateTimeList == null ||localDateTimeList.isEmpty()){continue;

}

List dayWrapperList = new ArrayList<>();

localDateTimeList.stream().forEach(localDateTime->{

DayWrapper dayWrapper= newDayWrapper(localDateTime);

dayWrapperList.add(dayWrapper);

dayMap.put(DateTimeFormatterUtil.formatToDateStr(localDateTime), dayWrapper);

});

MonthWrapper monthWrapper= newMonthWrapper(i, dayWrapperList);

monthWrapperList.add(monthWrapper);

}

List yearWrapperList = new ArrayList<>();

YearWrapper yearWrapper= newYearWrapper(year, monthWrapperList);

yearWrapperList.add(yearWrapper);

calendarWrapper= newCalendarWrapper(yearWrapperList, dayMap);returncalendarWrapper;

}

}

 类似资料: