对于时间的灵活操作

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);  

  }

}

posted on 2014-06-17 21:06  ★丶下面有请゛  阅读(110)  评论(0编辑  收藏  举报

导航