A little Scala “date” utilities class

Here’s some source code for a little Scala “date utilities” class:

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

object DateUtils {

    val DATE_FORMAT = "EEE, MMM dd, yyyy h:mm a"

    def getDateAsString(d: Date): String = {
        val dateFormat = new SimpleDateFormat(DATE_FORMAT)
        dateFormat.format(d)
    }

    def convertStringToDate(s: String): Date = {
        val dateFormat = new SimpleDateFormat(DATE_FORMAT)
        dateFormat.parse(s)
    }
    
    def convertDateStringToLong(dateAsString: String): Long = {
        convertStringToDate(dateAsString).getTime
    }
    
    def convertLongToDate(l: Long): Date = new Date(l)
    
    def now(): Date = Calendar.getInstance.getTime

}

If you wanted to see how to do some things with dates in Scala, or otherwise want to start your own date utilities class, I hope this example source code is helpful.