Java Date to Month getMonthRate(Date date, boolean moveIn)

Here you can find the source of getMonthRate(Date date, boolean moveIn)

Description

get Month Rate

License

Apache License

Declaration

public static String getMonthRate(Date date, boolean moveIn) 

Method Source Code

//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);
    }
}

Related

  1. getMonthOffset(Date sourceDate, Date targetDate)
  2. getMonthOfThisYear(Date currentdate)
  3. getMonthOfYear(Date date)
  4. getMonthOfYear(Date dt)
  5. getMonthOfYear(final Date date)
  6. getMonths(Date date1, Date date2)
  7. getMonthStart(Date date)
  8. getMonthStart(Date date)
  9. getMonthStartDay(Date date)