Java Year Month getYearMonth(String year)

Here you can find the source of getYearMonth(String year)

Description

get Year Month

License

Apache License

Declaration

public static List<String> getYearMonth(String year) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import java.util.Date;
import java.util.List;

public class Main {
    private static SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");

    public static List<String> getYearMonth(String year) {
        if (null == year || "".equals(year.trim())) {
            year = yearFormat.format(new Date());
        }// w ww .  j av  a  2 s.  co  m
        List<String> yearMonth = new ArrayList<String>();

        int currentYear = Integer.parseInt(year);
        int lastYear = Integer.parseInt(year) - 1;

        for (int j = currentYear; j >= lastYear; j--) {
            for (int i = 12; i >= 1; i--) {
                yearMonth.add(j + "-" + String.format("%02d", i));
            }
        }

        return yearMonth;
    }
}

Related

  1. getYearMonth()
  2. getYearMonth(Calendar sDate)
  3. getYearMonth(Date date)
  4. getYearMonth(Date date)
  5. getYearMonth(String dateString)
  6. getYearMonthDate()
  7. getYearMonthDateByMisSecond(long misSecond)
  8. getYearMonthDay()
  9. getYearMonthDay(Date date)