Java Date Before getMonthStartDateBeforeCurrent(int monthNum, Date current)

Here you can find the source of getMonthStartDateBeforeCurrent(int monthNum, Date current)

Description

get Month Start Date Before Current

License

Apache License

Declaration

public static long getMonthStartDateBeforeCurrent(int monthNum, Date current) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;

import java.util.Date;

public class Main {

    public static long getMonthStartDateBeforeCurrent(int monthNum, Date current) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(current);/*from   w  w w  .ja  v a  2 s .  c  o  m*/

        // calendar.set(Calendar.MONTH, -monthNum + 2);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        calendar.add(Calendar.MONTH, -monthNum);

        return calendar.getTimeInMillis();
    }
}

Related

  1. getDayFormSomeDay(Date date, int n, boolean before)
  2. getDistanceMonthOfTwoDate(Date before, Date after)
  3. getMinuteBefore(Date date, int minute)
  4. getMonth(Date time, int monthBefore, int monthAfter)
  5. getMonthBefore(Date currentDate, int numberMonthBefore)
  6. getOneHourBefore(Date date)
  7. getPassedMonthBetweenDate(Date before, Date after)
  8. getPreviousDate(String before)
  9. getQuarterStartDateBeforeCurrent(int num, Date current)