I asked a question regarding this here. It works fine and is a nice solution, however I just realized that in some cases when java 1.8 is NOT installed import java.time
is not available. I have java 1.7 and cannot update due many other issues.
after java 1.8
import java.time.{LocalDate, Year}
def allDaysForYear(year: String): List[(String, String, String)] = {
val daysInYear = if(Year.of(year.toInt).isLeap) 366 else 365
for {
day <- (1 to daysInYear).toList
localDate = LocalDate.ofYearDay(year.toInt, day)
month = localDate.getMonthValue
dayOfMonth = localDate.getDayOfMonth
} yield (year, month.toString, dayOfMonth.toString)
}
older java versions:
so, for instance using import java.util.{Calendar}
how can the same issue be solved? -> Get all months and days for a given year
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…