Here you can find the source of getYearMonth(Date date)
public static String getYearMonth(Date date)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static String getYearMonth(Date date) { Calendar c = new GregorianCalendar(); c.setTime(date);/*from w ww .j a v a 2 s . co m*/ return c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1); } }