Computer scienceProgramming languagesKotlinAdditional instrumentsAdditional libraries

Libraries overview

New date

Report a typo

We have a function addDaysToDate that receives the number of days we want to add to a given date and outputs the new date.

Import the right packages to make the code below work correctly.

Tip: Solving this problem using the IDE will make it easier.

Sample Input 1:

August 17, 2023
10

Sample Output 1:

August 27, 2023
Write a program in Kotlin
// Do NOT modify the following function
fun addDaysToDate(inputDate: String, inputDays: Int): String {
val dateFormat = DateFormat.getDateInstance(DateFormat.LONG)

val calendar = Calendar.getInstance()
val date = dateFormat.parse(inputDate)
calendar.time = date
calendar.add(Calendar.DATE, inputDays)
val newDate = calendar.time
return dateFormat.format(newDate)
}

Create a free account to access the full topic