SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String yuechu = null;//月初
String yuemo = null;//月末
Calendar c = Calendar.getInstance(Locale.CHINA);
Date time = new Date();
c.setTime(time);
c.setTime(time);
c.set(Calendar.HOUR_OF_DAY, 0);
// 分
c.set(Calendar.MINUTE, 0);
// 秒
c.set(Calendar.SECOND, 0);
// 毫秒
c.set(Calendar.MILLISECOND, 0);
c.add(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH, 1);//设置为1号,当前日期既为本月第一天
yuechu = sdf.format(c.getTime());
System.out.println(“本月第一天+++++++++++++” + yuechu);
//本月最后一天
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
c.add(Calendar.DAY_OF_MONTH, 1);
yuechu = sdf.format(c.getTime());
System.out.println(“下月第一天+++++++++++++” + yuechu);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
c.add(Calendar.DAY_OF_MONTH, 1);
yuemo = sdf.format(c.getTime());
System.out.println(“下下月第一天+++++++++++++” + yuemo);
获取下月的第一天和下下月的第一天
最新推荐文章于 2021-04-14 02:00:49 发布