tl;dr
LocalDate.of( 2018 , Month.JANUARY , 23 )
.minusDays( … )
java.time
You are using troublesome old date-time classes that are now legacy, supplanted by the java.time classes.
Use LocalDate
for a date-only without time-of-day.
Using the Month
enum.
LocalDate start = LocalDate.of( 2018 , Month.JANUARY , 23 ) ; // 2018-01-23.
Using month numbers, 1-12 for January-December.
LocalDate start = LocalDate.of( 2018 , 1 , 23 ) ; // 2018-01-23.
Collect a sequence of dates.
List<LocalDate> dates = new ArrayList<>( 7 ) ;
for( int i = 1 ; i <= 7 ; i ++ ) {
LocalDate ld = start.minusDays( i ) ; // Determine previous date.
dates.add( ld ) ; // Add that date object to the list.
}
For earlier Android, use the ThreeTen-Backport and ThreeTenABP projects.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…