How to set hours, minutes, seconds for date object in android

I have Date object like this -> Sat Jun 26 00:00:00 IST 2021 I want to set hours, minutes, seconds like this -> Sat Jun 26 23:59:59 IST 2021

In Android

Answer

You can do that with Calendar.

val calendar = Calendar.getInstance()
calendar.time = Date() // Set your date object here
    
calendar.set(Calendar.HOUR_OF_DAY, 23)
calendar.set(Calendar.MINUTE, 59)
calendar.set(Calendar.SECOND, 59)
calendar.time // Your changed date object