guys actually my logic is that I want to basically show a current month with the last three months in tab layout which I am using to show the months wise data to the user so if present its "June" so I want to show tabs "April, May, June" these 3 months data to the user.
Consider using java.time, the modern Java date and time API, for your date work. Sorry that I can write only Java.
Month thisMonth = Month.from(YearMonth.now(ZoneId.systemDefault()));
List<Month> months
= Arrays.asList(thisMonth.minus(2), thisMonth.minus(1), thisMonth);
for (Month m : months) {
System.out.println(m.getDisplayName(TextStyle.FULL_STANDALONE, Locale.ENGLISH));
}
Output when running this month:
April May June
And don’t worry: this will work across New Year too. January minus 2 months will be November, for example.
java.time works nicely on both older and newer Android devices. It just requires at least Java 6.
org.threeten.bp
with subpackages.java.time
was first described.java.time
to Java 6 and 7 (ThreeTen for JSR-310).