Skip to content

Instantly share code, notes, and snippets.

@NIA
Last active December 25, 2015 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NIA/6897097 to your computer and use it in GitHub Desktop.
Save NIA/6897097 to your computer and use it in GitHub Desktop.
Getting time diffs using https://github.com/scalaj/scalaj-time (JodaTime wrapper for scala)
scalaVersion := "2.9.2"
mainClass := Some("Main")
libraryDependencies += "org.scalaj" %% "scalaj-time" % "0.6"
// locate this in src/main/scala/ to compile with sbt
import org.joda.time.Period
import org.joda.time.format.PeriodFormat
import org.scala_tools.time.Imports._
object Main extends App {
def periodDiff(t1: Period)(t2: Period) = PeriodFormat.getDefault print (t1 - t2).normalizedStandard
println( periodDiff(2.hours + 14.minutes + 39.seconds)(1.hour + 32.minutes + 43.seconds) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment