Here you can find the source of getMonthString(Date date)
public static String getMonthString(Date date)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public final static String monthFormat = "yyyyMM"; public static String getMonthString(Date date) { DateFormat dateFormat = createNewDateFormat(monthFormat); return formatDateString(date, dateFormat); }//w w w .j a v a 2 s. c o m public static DateFormat createNewDateFormat(String pattern) { DateFormat df = new SimpleDateFormat(pattern); df.setLenient(false); return df; } public static String formatDateString(Date date, DateFormat dateFormat) { if (date == null || dateFormat == null) { return null; } return dateFormat.format(date); } public static String format(Date date, String format) { if (date == null) { return null; } return new SimpleDateFormat(format).format(date); } }