Created
January 7, 2016 21:29
-
-
Save ldacosta/d3a8031777fd901bdb4e to your computer and use it in GitHub Desktop.
Getting used to calculations with JODA DateTime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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