Here you can find the source of getCurrentMonth()
public static String getCurrentMonth()
//package com.java2s; import java.util.*; import java.text.*; public class Main { public static SimpleDateFormat monthFormat = new SimpleDateFormat("MM"); public static String getCurrentMonth() { Date current = new Date(System.currentTimeMillis()); return monthFormat.format(current); }/*from w w w.j a va2s.c o m*/ public static String getCurrentMonth(String date) { String currentMonth; date = deleteSlash(date); int year = getYear(date); int month = getMonth(date); Calendar tmpCalendar = Calendar.getInstance(); currentMonth = Integer.toString(tmpCalendar.get(Calendar.YEAR)); if ((tmpCalendar.get(Calendar.MONTH) + 1) < 10) currentMonth += "0"; currentMonth += Integer.toString((tmpCalendar.get(Calendar.MONTH)) + 1); return currentMonth; } public static String deleteSlash(String value) { return deleteChar(value, "/"); } public static int getYear(String date) { date = deleteSlash(date); date = deleteDash(date); return Integer.parseInt(date.substring(0, 4)); } public static int getMonth(String date) { date = deleteSlash(date); date = deleteDash(date); return Integer.parseInt(date.substring(4, 6)); } public static String deleteChar(String source, String deleteStr) { if (source == null || "".equals(source.trim())) { return ""; } StringBuffer temp = new StringBuffer(""); StringTokenizer st = new StringTokenizer(source, deleteStr); while (st.hasMoreTokens()) { temp.append(st.nextToken()); } return temp.toString(); } public static String deleteDash(String value) { return deleteChar(value, "-"); } }