我用System.out.println(calendar);得到了GregorianCalendar 的结果:java.util.GregorianCalendar[time=1158930431859,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2006,MONTH=8,WEEK_OF_YEAR=38,WEEK_OF_MONTH=4,DAY_OF_MONTH=22,DAY_OF_YEAR=265,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=9,HOUR_OF_DAY=21,MINUTE=7,SECOND=11,MILLISECOND=859,ZONE_OFFSET=28800000,DST_OFFSET=0]
发现这得到的格林威治时间中,的日期原来是与此排布的,它只是先生成一个数组而已,至于以后的calendar.getTime();直接调用久行了,此时我才恍然大悟,这样的话就简单多了!
所以我就试着把输入的部分改为:Scanner input=new Scanner(System.in);int year=input.nextInt();int month=input.nextInt();int day=input.nextInt();GregorianCalendar calendar=new GregorianCalendar(year,month-1,day); 再System.out.println(calendar);就可以得到如下的结果了:java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=2006,MONTH=9,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
这才解决了,我所要解决的问题,好兴奋啊!只是那个month-1,我试了好几次才试出来,原来是输入月份9,在GregorianCalendar的数组中为第八个的位置,所以才是这样的结果。
现在发现编程序也有许多快乐,继续努力啊!