CraneageHu

导航

一、日期

使用Hutool日期工具包DateUtil

  1. 获得某天最大时间

public static Date getEndOfDay(Date date) {

if (date == null) {date = new Date();}
return DateUtil.endOfDay(date); // 2023-05-23 23:59:59
}

  1. 获取某天最小时间

public static Date getBeginOfDay(Date date) {

if (date == null) {date = new Date();}
return DateUtil.beginOfDay(date); // 2023-05-23 00:00:00
}

  1. 获取下一个月日期

public static final String getNextMonth(String queryMonth) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");

Calendar calendar = Calendar.getInstance();
// 设置为当前时间
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");

Date month = dateFormat.parse(queryMonth);
calendar.setTime(month);
calendar.add(Calendar.MONTH,1);

Date date = calendar.getTime();
return format.format(date);
}

posted on 2023-05-23 11:11  CranageHu  阅读(116)  评论(0)    收藏  举报