calendar

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.

How to create a Java or Scala date from a Long value

Scala FAQ: How do I created a Scala Date from a Long value? When I give the Java Date class constructor a Long value it returns a date from 1970.

Solution: You need to multiply the Long value by 1000, and also make sure you pass a Long value into the Date constructor. The Scala REPL shows how this works:

Scala: How to get the current month as a number or string

Table of Contents1 - Get the current month as an integer number2 - How to get the current month as an abbreviated string3 - How to get the full month name4 - A note about SimpleDateFormat and Locale5 - Summary

Scala FAQ: How do I get the current month as an integer or as a string in Scala?

This is a page from my book, “How I Sold My Business: A Personal Diary”

Sunday, April 30, 2006

Somewhere along the way I managed to look at the calendar for the wrong year: This year April 28 was the last Friday in April, and also my last day with the company I founded so many years ago. As I'm getting ready to leave town this coming Tuesday, this last week was filled with very little work, and many goodbye visits with former employees, clients, and other friends outside of the business.