java.util.Date date = new Date();
int day = date.getDate();
int month = date.getMonth();
int year = date.getYear()+1900;
if (day<dayfrom) {
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMM");
    retYearAndMonth = sdf.format(date);
}
else {
    month++;
    if(month>12){
        year++;
        month = 1;
    }
    retYearAndMonth = year+""+(month>9 ? ""+month : "0"+month);
}

解决方案 »

  1.   

    不好意思,else那里错了,自己改改就可以了^&^
      

  2.   

    my last source:
     public int getNowMonth(int dayfrom){
        String retYearAndMonth = null;
        String retMonth = null;
       java.util.Date date = new java.util.Date();
       int day = date.getDate();
       int month = date.getMonth();
       int year = date.getYear()+1900;
       if (day<dayfrom) {
         return year*100+month+1;
       }
       else
       {
         return (year+(month+1)/12)*100+(month+1)%12+1;
         }
      }
      

  3.   

    谢谢天平,第一个方法在else那里确实出错了,并且走了很多的弯路,呵呵~~~~~~~~`