日期Calendar
import java.util.*; import java.text.*; class DateDemo { public static void main(String[] arhgs) { String[] month={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}; String[] week={"","星期一","星期二","星期三","星期四","星期五","星期六","星期日"}; Calendar cl=Calendar.getInstance(); int index=cl.get(Calendar.MONTH); int indexweek=cl.get(Calendar.WEEK_OF_MONTH); sop(cl.get(Calendar.YEAR)+"年"+cl.get(Calendar.MONTH)+"月"+cl.get(Calendar.DAY_OF_MONTH)+"日"); sop(month[index]); sop(week[indexweek]); /* * Date d=new Date(); sop(d); SimpleDateFormat sdf=new SimpleDateFormat("yyyy年"); String obj=sdf.format(d); sop(obj); **/ } public static void sop(Object obj) { System.out.println(obj); } }
Calendar cl=Calendar.getInstance();
// cl.set(2011,3,3);
cl.add(Calendar.MONTH,-4);
sop(cl.get(Calendar.YEAR)+"年"+cl.get(Calendar.MONTH)+"月"+cl.get(Calendar.DAY_OF_MONTH)+"日");