How to format time hours-minutes-seconds in Scala

1 Answer

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

object FormattedTimeApp {
  def main(args: Array[String]): Unit = {
    // Get the current time
    val currentTime: LocalTime = LocalTime.now()

    // Format the time as "HH:MM:SS"
    val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss")
    val formattedTime: String = currentTime.format(formatter)

    println(s"Formatted Time: $formattedTime")
  }
}



/*
run:
 
Formatted Time: 19:02:47
 
*/
 

 



answered Jul 22, 2025 by avibootz
...