I want to get the date from 7 days ago to today in Kotlin. Any suggestions? This is what I have so far.
Use this function, to get the date of the days you have passed;
fun getDaysAgo(daysAgo: Int): Date {
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, -daysAgo)
return calendar.time
}
or in this way.
val date = Calendar.getInstance() // 19-01-2018
date.add(Calendar.DATE, -7) // 12-01-2018
or it could be like this.
DateTime.now().minusDays(7)
Done.