In Scala, how to get the day of the year

Scala date FAQ: How do I determine the day of the year in Scala?

Solution: Use the Java Calendar class, as shown here:

scala> import java.util.Calendar
import java.util.Calendar

scala> Calendar.getInstance.get(Calendar.DAY_OF_YEAR)
res0: Int = 104

I’m writing this on April 14, 2018, which is the 104th day of the year.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.