所以这是一个旧代码,应该检查收到的传真但由于某种原因我找不到错误。
Calendar receivedAfter = Calendar.getInstance();
receivedAfter.add(Calendar.DAY_OF_YEAR, -14);
System.out.println();
System.out.println("Checking for received faxes since : " + receivedAfter);
我的输出是
检查收到的传真:
java.util.GregorianCalendar[time=1386017803339,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=11,WEEK_OF_YEAR=49,WEEK_OF_MONTH=1,DAY_OF_MONTH=2,DAY_OF_YEAR=336,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=3,HOUR_OF_DAY=15,MINUTE=56,SECOND=43,MILLISECOND=339,ZONE_OFFSET=-18000000,DST_OFFSET=0]
为什么打印出所有这些数据? 有什么建议吗?
答案 0 :(得分:1)
这是toString()
内GregorianCalendar
方法的默认实现。
快速替代方案,不做大量的日期格式化,将是:
System.out.println("Checking for received faxes since : " + receivedAfter.getTime());
这为您提供了一个java.util.Date对象,该对象具有更人性化的toString()
方法。
答案 1 :(得分:0)
这是整个对象。您可能想要从对象中获取特定字段。试试
System.out.println("Checking for received faxes since : " + receivedAFter.YEAR() + '/' + receivedAfter.MONTH() + '/' + receivedAfter.DAY_OF_MONTH());