Here you can find the source of getThisYearMonth()
public static String getThisYearMonth() throws ParseException
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.util.Calendar; import java.util.Date; public class Main { public static String getThisYearMonth() throws ParseException { return getYearMonth(new Date()); }// w w w. j ava 2s . c o m public static String getYearMonth(Date date) { Calendar today = Calendar.getInstance(); today.setTime(date); return (today.get(Calendar.YEAR)) + "-" + ((today.get(Calendar.MONTH) + 1) >= 10 ? (today.get(Calendar.MONTH) + 1) : ("0" + (today.get(Calendar.MONTH) + 1))); } }