StringBuffer sb = new StringBuffer(); Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月"); Date date = calendar.getTime();//获取当前年月 sb.append(format.format(date)+"\n"); for (int i=0;i<6;i++){ calendar.add(Calendar.MONTH,-1);//每次月数减一,如果需要当前月份以后的就填1 date = calendar.getTime(); sb.append(format.format(date)+"\n"); } TextView tv = (TextView) findViewById(R.id.tv_main); tv.setText(sb.toString());
效果图