Here you can find the source of getStartAndEndWeekOfMonth(int year, int month, int week, String format)
public static String[] getStartAndEndWeekOfMonth(int year, int month, int week, String format)
//package com.java2s; import java.util.*; import java.text.*; public class Main { public static String[] getStartAndEndWeekOfMonth(int year, int month, int week, String format) { SimpleDateFormat formater = new SimpleDateFormat(format); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DATE, 0); int lastWeek = calendar.get(Calendar.WEEK_OF_MONTH); if (week > lastWeek) return null; String lastDate = formater.format(calendar.getTime()); String[] result = new String[2]; calendar.set(Calendar.WEEK_OF_MONTH, week); calendar.set(Calendar.DAY_OF_WEEK, 1); if (week == 1) calendar.set(Calendar.DATE, 1); result[0] = formater.format(calendar.getTime()); if (lastWeek == week) { result[1] = lastDate;//ww w.j a v a 2 s . c o m } else { calendar.set(Calendar.DAY_OF_WEEK, 7); result[1] = formater.format(calendar.getTime()); } return result; } public static Date getTime(String hhmm) { if (hhmm != null && hhmm.length() == 4 && isDigit(hhmm)) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hhmm.substring(0, 2))); cal.set(Calendar.MINUTE, Integer.parseInt(hhmm.substring(2, 4))); return cal.getTime(); } return null; } private static boolean isDigit(String digitStr) { if (digitStr != null) { for (int i = 0; i < digitStr.length(); i++) if (!Character.isDigit(digitStr.charAt(i))) return false; } return true; } }