Some Scala Long, Date, and SimpleDateFormat examples

At some point I’ll get all of my Scala “date utilities” together in a single class (object, actually), but until then, here are a couple of date utility methods I wrote for my Scrupal6 project (a replacement for Drupal 6):


import java.text.SimpleDateFormat
import java.util.Date

object DateUtils {

    def formatDateForBlogPages(date: Long): String = {
        val d = new Date(date * 1000L)
        new SimpleDateFormat("LLLL d, yyyy").format(d)
    }

    def formatDateForSitemap(date: Long): String = {
        val d = new Date(date * 1000L)
        new SimpleDateFormat("yyyy-MM-d").format(d)
    }

}

I thought I’d share them here so they might serve as another example of how to use classes like Date and SimpleDateFormat with Scala. One important note about them is that Drupal 6 ran on PHP, and they stored dates as what would be Scala Long values, and the precision isn’t the same as what Java and Scala use, so the 1000L multiplier was necessary to make these work.