Java Year Month getYearMonths(List time)

Here you can find the source of getYearMonths(List time)

Description

Get year months

License

LGPL

Parameter

Parameter Description
time Date list

Return

Year month list

Declaration

public static List<String> getYearMonths(List<Date> time) 

Method Source Code

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

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

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

public class Main {
    /**//ww w . j  a  v a2 s.com
     * Get year months
     *
     * @param time Date list
     * @return Year month list
     */
    public static List<String> getYearMonths(List<Date> time) {
        List<String> yms = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
        String ym;
        for (Date t : time) {
            ym = format.format(t);
            if (!yms.contains(ym)) {
                yms.add(ym);
            }
        }

        return yms;
    }
}

Related

  1. getYearMonthDateByMisSecond(long misSecond)
  2. getYearMonthDay()
  3. getYearMonthDay(Date date)
  4. getYearMonthDay(final int year, final int month, final int day)
  5. getYearMonthList(int year)
  6. getYearMonthStr(Date parseDate)
  7. getYearMonthString(Date date)
  8. lastDay(int year, int month)
  9. makeDate(int day, int month, int year, int hour, int min, int sec)