方式共有两种,使用java.util.Calendar日历类实现
第一种:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");Date date = new Date();Calendar calendar = new GregorianCalendar();calendar.setTime(date);//获得本月第一天calendar.add(Calendar.MONTH, 0);calendar.set(Calendar.DAY_OF_MONTH, 1);String firstDay = sdf.format(calendar.getTime());System.out.println("firstDay:"+ firstDay);//获得本月最后一天calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));String lastDay = sdf.format(calendar.getTime());第二种:
Calendar cal = Calendar.getInstance();cal.setTime(new Date());cal.set(Calendar.DAY_OF_MONTH, 1);System.out.println (new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));cal.roll(Calendar.DAY_OF_MONTH, -1);System.out.println (new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));
参考文章:https://www.cnblogs.com/dongming-03/p/5628947.html
原文转载:http://www.shaoqun.com/a/497195.html
inkfrog:https://www.ikjzd.com/w/668
环球市场:https://www.ikjzd.com/w/1762
慧聪商务网:https://www.ikjzd.com/w/1836
方式共有两种,使用java.util.Calendar日历类实现第一种:SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");Datedate=newDate();Calendarcalendar=newGregorianCalendar();calendar.setTime(date);//获得本月第一天calendar.
jpgoodbuy:jpgoodbuy
1号团:1号团
亚马逊这项费用发生巨变!最高降30%!:亚马逊这项费用发生巨变!最高降30%!
马来西亚 沙巴潜水记 - :马来西亚 沙巴潜水记 -
成都到九寨沟飞机介绍 :成都到九寨沟飞机介绍