Calendar
1)Calendar c=Calendar.getInstance();
//方法返回一个 Calendar
对象,其日历字段已由当前日期和时间初始化
System.out.println("-------------@@@@@@@@@@@@@@@@@@@@@"+c);
结果为:-------------@@@@@@@@@@@@@@@@@@@@@java.util.GregorianCalendar[time=1335446966578,
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,//一周的第一天,如在美国的第一天是SUNDAY,
法国第一天是MONDAY
minimalDaysInFirstWeek=1,
ERA=1,//AD为1,BC 为 0
YEAR=2012,
MONTH=3,
WEEK_OF_YEAR=17,
WEEK_OF_MONTH=4,
DAY_OF_MONTH=26,
DAY_OF_YEAR=117,
DAY_OF_WEEK=5,
DAY_OF_WEEK_IN_MONTH=4,//此周是当前月的第几周
AM_PM=1,
HOUR=9,
HOUR_OF_DAY=21,
MINUTE=29,
SECOND=26,
MILLISECOND=578,
ZONE_OFFSET=28800000,
DST_OFFSET=0]
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
2)Date dd=c.getTime();
System.out.println("------------yangyangyang------->"+dd);
结果为:------------yangyangyang------->Thu Apr 26 21:29:26 CST 2012
System.out.println("------------yangyangyang------->"+sdf.format(dd));
结果为:------------yangyangyang------->2012-04-26
3)Date df=new Date();
System.out.println("------------羊羊羊------->"+df);
System.out.println("------------羊羊羊------->"+sdf.format(df));
结果为:------------羊羊羊------->Thu Apr 26 21:29:26 CST 2012
System.out.println("------------羊羊羊------->"+sdf.format(dd));
结果为:------------羊羊羊------->2012-04-26
4)c.set(Calendar.YEAR, 2012);
c.set(Calendar.MONTH,0);
c.set(Calendar.DATE, 1);
System.out.println("
-------------@@@@@@@@@@@@@@@@@@@@@"+c);
firstDayOfWeek=1,
minimalDaysInFirstWeek=1,
ERA=1,
YEAR=2012,
MONTH=0,
WEEK_OF_YEAR=17,
WEEK_OF_MONTH=4,
DAY_OF_MONTH=1,
DAY_OF_YEAR=117,
DAY_OF_WEEK=5,
DAY_OF_WEEK_IN_MONTH=4,
AM_PM=1,
HOUR=9,
HOUR_OF_DAY=21,
MINUTE=29,
SECOND=26,
MILLISECOND=578,
ZONE_OFFSET=28800000,
DST_OFFSET=0]
4)calendar 中的月从0开始
c.set(Calendar.YEAR, iyear);
c.set(Calendar.MONTH,0);
c.set(Calendar.DATE, 1);
System.out.println("-------------@@@@@@@@@@@@@@@@@@@@@"+sdf.format(c.getTime()));