0

i am using this libs CalnderView any one know how to get end and last date of month?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Possible duplicate of [java get the first date and last date of given month and given year](https://stackoverflow.com/questions/14475489/java-get-the-first-date-and-last-date-of-given-month-and-given-year) – Ole V.V. Sep 28 '18 at 09:05
  • I downvote because the question is unclear: this month, any month? As limits on the calendar view or just into your code? Also because I see no search, no research, no attempt to solve your problem yourself. – Ole V.V. Sep 28 '18 at 09:15
  • 1
    okay thanks for guide me i'll remember in future . – mykiee jass Oct 03 '18 at 05:59

2 Answers2

5

Its not about any library but you can get it as.

Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);

This returns actual maximum for current month.

SRB Bans
  • 3,096
  • 1
  • 10
  • 21
  • why people give down vote on my question ? is it wrong question? – mykiee jass Sep 28 '18 at 06:41
  • @mykieejass sometimes people don't do that... thats the question asking standard of SOF... read about that in description of sof.. :) – SRB Bans Sep 28 '18 at 06:43
  • That’s the old-fashioned way. You may prefer `LocalDate.now(yourTimeZone).with(TemporalAdjusters.lastDayOfMonth())`. If your Android version is new (API level 26 or higher) or you can afford an external library (search for ThreeTenABP). – Ole V.V. Sep 28 '18 at 09:19
2
Used getDaterange method to get the stat and end date in month. its work for me.

public Pair<Date, Date> getDateRange() {
    Date begining, end;

    {
        Calendar calendar = getCalendarForNow();
        calendar.set(Calendar.DAY_OF_MONTH,
                calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
        setTimeToBeginningOfDay(calendar);
        begining = calendar.getTime();
    }

    {
        Calendar calendar = getCalendarForNow();
        calendar.set(Calendar.DAY_OF_MONTH,
                calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        setTimeToEndofDay(calendar);
        end = calendar.getTime();
    }

    return Pair.of(begining, end);
}

private static Calendar getCalendarForNow() {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(new Date());
    return calendar;
}

private static void setTimeToBeginningOfDay(Calendar calendar) {
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
}

private static void setTimeToEndofDay(Calendar calendar) {
    calendar.set(Calendar.HOUR_OF_D`enter code here`AY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);
}
Jaydeep Chauhan
  • 146
  • 2
  • 6