A little Scala “date” utilities class

Nothing major here today, but here’s some source code to start 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)

    def convertStringToDate(s: String): Date = {
        val dateFormat = new SimpleDateFormat(DATE_FORMAT)
    def convertDateStringToLong(dateAsString: String): Long = {
    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.

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.