How to convert time in milliseconds to number of years in Scala

1 Answer

0 votes
import java.util.Calendar

object TimeInMillisecondsToNumberOfYears_Scala {
  def main(args: Array[String]): Unit = {
    val cal = Calendar.getInstance()

    // Set time in milliseconds
    cal.setTimeInMillis(1476907455894L)

    val totalYears: Int = cal.get(Calendar.YEAR) - 1970
    println(totalYears)

    val year: Int = cal.get(Calendar.YEAR)
    println(year)
  }
}



/*
run:

46
2016

*/

 



answered Oct 5, 2024 by avibootz

Related questions

...