Here you can find the source of getDayOfPerMonth(String theDataStr)
public static Date getDayOfPerMonth(String theDataStr)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { private static final int[] DAY_OF_MONTH = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public static Date getDayOfPerMonth(String theDataStr) { Date theDate = java.sql.Date.valueOf(theDataStr); Calendar c = new GregorianCalendar(); c.setTime(theDate);/*from w w w. j a v a 2s . c om*/ int day = c.get(Calendar.DAY_OF_MONTH); if (day <= 10) { c.set(Calendar.DAY_OF_MONTH, 1); } else if (day > 10 && day <= 20) { c.set(Calendar.DAY_OF_MONTH, 11); } else { c.set(Calendar.DAY_OF_MONTH, 21); } c.add(Calendar.DAY_OF_MONTH, -1); return new Date(c.getTime().getTime()); } public static int get(Date date, int type) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(type); } public static String getTime(Date dt, String format) { SimpleDateFormat st = new SimpleDateFormat(format); return st.format(dt); } }