问题:求某一时间点A的前前两个月的时间,A是一个时间点,有可能是任何时间,例如: 2011-05-04   2011-03-08

解决方案 »

  1.   

    你回复的真快,谢谢!    String 类型的字符串 ”2011-03-05“ 如何转换成Calendar?  如果是Calendar我会取出前两个月的时间, 能说下String类型的字符串转换成Calendar吗?   
      

  2.   

    String转成Date用DateSimpleFormat这个类
    Calendar cal  = Calendar.getInstance();
    cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2011-04-22"));
    have a try
      

  3.   


               public String getTime(int year,int month,int Nowdate){
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
                    Date date = new Date();
    date.setYear(year);
    date.setMonth(date.getMonth()-2); //设置月份
    date.setDate(Nowdate);                String time = sdf.format(date);
                  }
     
      

  4.   

    谢谢你 viszl  你的方法可行!  
      

  5.   

    你的方法需要改进,当year=2011时,计算出的time= 3911-03-04  很明显不正确。当你也提供了另一种思路,ok!  谢谢