Java获取当前月的上一个月的第一天和最后一天

  • Post author:
  • Post category:java



package cn.hutool.core.date;

<dependency>
	<groupId>cn.hutool</groupId>
	<artifactId>hutool-all</artifactId>
	<version>5.2.4</version>
</dependency>

SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date); // 设置为当前时间
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
date = calendar.getTime();
DateTime beginMonth= DateUtil.beginOfMonth(date);
DateTime endMonth= DateUtil.endOfMonth(date);
System.out.println("start="+beginMonth+",end="+endMonth);



版权声明:本文为weixin_47314019原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。