Here you can find the source of getMonthRate(Date date, boolean moveIn)
public static String getMonthRate(Date date, boolean moveIn)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static String getMonthRate(Date date, boolean moveIn) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w ww. jav a 2s . c o m*/ int day = calendar.get(5); int daysOfThisMonth = calendar.getActualMaximum(5); double rate; if (moveIn) rate = (daysOfThisMonth - day + 1) / daysOfThisMonth; else { rate = day / daysOfThisMonth; } rate = Math.round(rate * 10.0D) / 10.0D; return String.valueOf(rate); } public static String getMonthRate(Date dateIn, Date DateOut) { Calendar calIn = Calendar.getInstance(); calIn.setTime(dateIn); Calendar calOut = Calendar.getInstance(); calOut.setTime(DateOut); int day = calOut.get(5) - calIn.get(5) + 1; int daysOfThisMonth = calIn.getActualMaximum(5); double rate = day / daysOfThisMonth; rate = Math.round(rate * 10.0D) / 10.0D; return String.valueOf(rate); } }