Skip to content

Instantly share code, notes, and snippets.

@ldacosta
Created January 7, 2016 21:29
Show Gist options
  • Save ldacosta/d3a8031777fd901bdb4e to your computer and use it in GitHub Desktop.
Save ldacosta/d3a8031777fd901bdb4e to your computer and use it in GitHub Desktop.
Getting used to calculations with JODA DateTime
import com.github.nscala_time.time.Imports._
import org.joda.time.Days
val nowInToronto:DateTime = DateTime.now(DateTimeZone.forID("America/Toronto"))
val nowInTorontoInUTC: DateTime = new org.joda.time.DateTime( nowInToronto, DateTimeZone.UTC)
println(nowInToronto.toString)
println(nowInTorontoInUTC.toString)
assert(Days.daysBetween( nowInToronto, nowInTorontoInUTC ).getDays == 0)
// better still
val duration = new Duration( nowInToronto, nowInTorontoInUTC)
assert(duration.getStandardMinutes == 0)
assert(duration.getStandardHours == 0)
assert(duration.getStandardDays == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment