For Example I have the date: \"23/2/2010\" (23th Feb 2010). I want to pass it to a function which would return the day of week. How can I do this?
I
method below retrieves seven days and return short name of days in List Array in Kotlin though, you can just reformat then in Java format, just presenting idea how Calendar can return short name
private fun getDayDisplayName():List{
val calendar = Calendar.getInstance()
val dates= mutableListOf()
dates.clear()
val s= calendar.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US)
dates.add(s)
for(i in 0..5){
calendar.roll( Calendar.DATE, -1)
dates.add(calendar.getDisplayName(DAY_OF_WEEK, SHORT, Locale.US))
}
return dates.toList()
}
out put results like
I/System.out: Wed
Tue
Mon
Sun
I/System.out: Sat
Fri
Thu