JavaCalendar获取年、月、日、时间Calendarc=Calendar.getInstance(TimeZone.getTimeZone(GMT+08:00));//获取东八区时间intyear=c.get(Calendar.YEAR);//获取年intmonth=c.get(Calendar.MONTH)+1;//获取月份,0表示1月份intday=c.get(Calendar.DAY_OF_MONTH);//获取当前天数intfirst=c.getActualMinimum(c.DAY_OF_MONTH);//获取本月最小天数intlast=c.getActualMaximum(c.DAY_OF_MONTH);//获取本月最大天数inttime=c.get(Calendar.HOUR_OF_DAY);//获取当前小时intmin=c.get(Calendar.MINUTE);//获取当前分钟intxx=c.get(Calendar.SECOND);//获取当前秒SimpleDateFormats=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);StringcurDate=s.format(c.getTime());//当前日期System.out.println(当前时间:+year+-+month+-+day++time+:+min+:+xx);System.out.println(第一天和最后天:+first+,+last);System.out.println(当前日期curDate====:+curDate);输出结果:当前时间:2012-9-2522:50:54第一天和最后天:1,30当前日期curDate:2012-09-2522:50:54Calendar的计算c.add(Calendar.YEAR,1);c.add(Calendar.MONTH,1);c.add(Calendar.DAY_OF_MONTH,1);intyear2=c.get(Calendar.YEAR);intmonth2=c.get(Calendar.MONTH)+1;intday2=c.get(Calendar.DAY_OF_MONTH);intfirstD=c.getActualMinimum(c.DAY_OF_MONTH);intlastD=c.getActualMaximum(c.DAY_OF_MONTH);System.out.println(当前时间:+year2+-+month2+-+day2++time+:+min+:+xx);System.out.println(第一天和最后天:+firstD+,+lastD);输出结果:当前时间:2013-10-2623:4:3第一天和最后天:1,31获取上个月的年、月、日Calendarc=Calendar.getInstance();c.add(Calendar.MONTH,-1);//上个月SimpleDateFormats=newSimpleDateFormat(yyyy-MM-ddHH:mm:ss);Stringyear=String.valueOf(c.get(Calendar.YEAR));StringtopDay=String.valueOf(c.getActualMinimum(Calendar.DAY_OF_MONTH));StringlastDay=String.valueOf(c.getActualMaximum(Calendar.DAY_OF_MONTH));//上个月StringlastMonth=String.valueOf(c.get(Calendar.MONTH)+1).length()==2?String.valueOf(c.get(Calendar.MONTH)+1):0+String.valueOf(c.get(Calendar.MONTH)+1);StringtopDayMonth=year+-+lastMonth+-+01+00:00:00;StringlastDayMonth=year+-+lastMonth+-+lastDay+23:59:59;System.out.println(###year:+year);System.out.println(###lastmonth:+lastMonth);System.out.println(###topday:+topDayMonth);System.out.println(###lastday:+lastDayMonth);输出结果###year:2013###lastmonth:04###topday:2013-04-0100:00:00###lastday:2013-04-3023:59:59转自