我想请教高手一个问题:我想实现这么一个下拉框,默认显示的是现在的月份,比方说是2006年1月.
然后其他显示是2005年11月,2005年12月,2006年1月,2006年2月,2006年3月五条记录,就是前两个月和后两个月的日期,这个该怎么实现啊? 我只知道取日期的代码:
Calendar cal=Calendar.getInstance();
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mDateTime=formatter.format(cal.getTime());
但是具体怎么算啊?谢谢了!!!

解决方案 »

  1.   

    calendar.setTime(new Date());
    //下一个月
    calendar.set(Calendar.MONTH,
                       calendar1.get(Calendar.MONTH) + 1);
      

  2.   

    Calendar cal=Calendar.getInstance();
    cal.setTime(new Date());//设置当前时间
    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1 );//cal.get(Calendar.MONTH)可以获取月份,比如当前时间1月,获取的值就为0,从0开始,然后加1后设置回cal里面
      

  3.   

    Calendar cal=Calendar.getInstance();
    int month = cal.get(Calendar.MONTH)+1;//当前月
    int year = cal.get(Calendar.YEAR);//当前年String option = "";
    if(month-1<0){
    options += "<option value='' >"+(year-1)+12+"</option>";}else{
    options += "<option value='' >"+year+(month-1)+"</option>";
    }
    options += "<option value='' selected>"+year+month+"</option>";....
    剩下的自己写吧