// 时间戳转Date,注意这里的时间戳是13位毫秒级的,如果是10位需要乘1000
Date longToDate = DateUtil.date(System.currentTimeMillis());
System.out.println(longToDate);
Date curDate = new Date();
// 获取今天开始时间和结束时间
Date startTimeDay = DateUtil.beginOfDay(curDate);
Date endTimeDay = DateUtil.endOfDay(curDate);
// 获取本月开始时间和结束时间
Date startTimeMonth = DateUtil.beginOfMonth(curDate);
Date endTimeMonth = DateUtil.endOfMonth(curDate);
// 获取本年开始时间和结束时间
Date startTimeYear = DateUtil.beginOfYear(curDate);
Date endTimeYear = DateUtil.endOfYear(curDate);
// Date转字符串(yyyy-mm-dd)
String dayStr = DateUtil.format(curDate, DatePattern.NORM_DATE_PATTERN);
System.out.println(dayStr);
// 字符串转Date(yyyy-MM-dd HH:mm:ss)
String dateStr = "2022-01-14 18:00:00";
Date date = DateUtil.parse(dateStr, DatePattern.NORM_DATETIME_PATTERN);
System.out.println(date);
// 时间偏移,正数则向后推,负数则向前倒
Date d1 = DateUtil.offsetHour(curDate, 12); // 时间向后推12个小时
Date d2 = DateUtil.offsetDay(curDate, -7); // 时间向前推一周
// 昨天
Date yesterday = DateUtil.yesterday();
// 明天
Date tomorrow = DateUtil.tomorrow();
// 上周
Date lastWeek = DateUtil.lastWeek();
// 下周
Date nextWeek = DateUtil.nextWeek();
// 上个月
Date lastMonth = DateUtil.lastMonth();
// 下个月
Date nextMonth = DateUtil.nextMonth();