根据设定时间前多少个月的月份

来源:互联网 发布:施耐德变频器调试软件 编辑:程序博客网 时间:2024/05/16 19:24
/*
     * 
     * 获取设定时间前多少个月的月份
     * 
     */  
    public static String[] getLastMonths(Date date, int month){  
    String[] getLastMonths = new String[month];  
       for(int i=0; i<month; i++){  
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
             Calendar calendar = Calendar.getInstance();// 日历对象
             calendar.setTime(date);// 设置当前日期
             calendar.add(Calendar.MONTH, -i);// 月份减一
             String aString = sdf.format(calendar.getTime());
       }  
        return getLastMonths;  
    }  
阅读全文
0 0
原创粉丝点击