Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cxcscmu avatar

Scala Java Time Handling

  • 1 installs
  • 77 repo stars
  • Updated July 9, 2026
  • cxcscmu/skilllearnbench

Reference for working with Java's LocalDate and LocalDateTime in Scala, including formatters and optional format strings for temporal tokenization.

About

Provides Scala snippets for using the Java time API (LocalDate, LocalDateTime, DateTimeFormatter) for temporal tokenization. A developer uses it as a quick reference for creating formatters and handling optional format patterns.

  • Formatter creation with ofPattern for ISO and date-only patterns
  • Handles optional format strings via Option matching

Scala Java Time Handling by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #1,366 of 1,879 Documentation skills by installs in the Skillselion catalog
  • Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/cxcscmu/skilllearnbench --skill scala-java-time-handling

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars77
Last updatedJuly 9, 2026
Repositorycxcscmu/skilllearnbench

What it does

Reference for working with Java's LocalDate and LocalDateTime in Scala, including formatters and optional format strings for temporal tokenization.

Files

SKILL.mdMarkdownGitHub ↗

Java Time API in Scala

Import Statements

import java.time.{LocalDate, LocalDateTime}
import java.time.format.DateTimeFormatter

Creating Formatters

// Predefined patterns
private val isoFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
private val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")

// Using formatter
val formatted = isoFormatter.format(localDateTime)

Handling Optional Format Strings

// Option for custom format
formatStr match {
  case Some(pattern) => DateTimeFormatter.ofPattern(pattern).format(value)
  case None => defaultFormatter.format(value)
}

// Or with getOrElse
val formatter = formatStr
  .map(DateTimeFormatter.ofPattern)
  .getOrElse(isoFormatter)
formatter.format(value)

Type Matching for Date/Time

value match {
  case dt: LocalDateTime => isoFormatter.format(dt)
  case d: LocalDate => dateFormatter.format(d)
  case _ => value.toString
}

ISO 8601 Standards

  • DateTime: yyyy-MM-dd'T'HH:mm:ss
  • Date: yyyy-MM-dd
  • Time: HH:mm:ss

Common Patterns

// Store formatter as val for reuse (thread-safe)
private val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")

// Format with fallback
def formatDate(date: LocalDate): String = {
  try {
    formatter.format(date)
  } catch {
    case _: Exception => date.toString
  }
}

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.