I have a list of Dates in format : dd-MM-yyyy
val tripDates = [03-03-2022, 05-03-2002, 23-02-2022]
Now I need to map this list to have not repeatable dates in format only : MM-yyyy
I have tryed to do this as a map:
val calendar = Calendar.getInstance()
val myFormat = "MM-yyyy"
val dateFormat = SimpleDateFormat(myFormat, Locale.US)
val formattedTrips = tripDates.map {
calendar.time = it
val month = calendar.get(Calendar.MONTH+1).toString()
val year = calendar.get(Calendar.YEAR).toString()
val monthAndYear = "$month-$year"
dateFormat.parse(monthAndYear)
}
But It doesnt work. I cannot make a new map. Any ideas?