Here you can find the source of getYearMonths(List
Parameter | Description |
---|---|
time | Date list |
public static List<String> getYearMonths(List<Date> time)
//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; } }