How to calculate the date six months from the current date in Scala

1 Answer

0 votes
import java.time.LocalDate
import java.time.format.DateTimeFormatter

object FutureDateCalculator extends App {
  def addMonthsToDate(months: Int, date: LocalDate = LocalDate.now()): LocalDate = {
    date.plusMonths(months)
  }

  val futureDate = addMonthsToDate(6)
  val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")

  println(s"Date six months from now: ${futureDate.format(formatter)}")
}


 
/*
run:

Date six months from now: 2025-12-12

*/

 



answered Jun 12, 2025 by avibootz
...