标签:class java get string set 时间
import java.util.*;
class Demo3 {
public static void main(String[] args) {
Calendar c=Calendar.getInstance();
//c.set(2012,4,23); //可以设置当前的时间
c.add(Calendar.MONTH,-7); //往前推7个月
c.add(Calendar.YEAR,-1);//往前推一年
printCalendar(c);
}
public static void printCalendar(Calendar c){
String[] mons={"一月","二月","三月","四月", "五月","六月","七月","八月", "九月","十月","十一月","十二月"};
String[] weeks={ "","星期日","星期一","星期二","星期三","星期四","星期五","星期六" };
int index = c.get(Calendar.MONTH);
int index1 = c.get(Calendar.DAY_OF_WEEK);
sop(c.get(Calendar.YEAR)+"年");
sop(mons[index]);
sop(weeks[index1]);
}
public static void sop(Object obj){
System.out.println(obj);
}
}
标签:class java get string set 时间
原文地址:http://www.cnblogs.com/dingzb/p/3793487.html