Skip to content

Instantly share code, notes, and snippets.

@olim7t
Created November 24, 2010 16:23
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 olim7t/713911 to your computer and use it in GitHub Desktop.
Save olim7t/713911 to your computer and use it in GitHub Desktop.
import java.util.Calendar._
import java.util.GregorianCalendar
import java.util.GregorianCalendar._
import java.util.TimeZone
// A calendar in Paris' time zone (GMT+1)
val cfr = new GregorianCalendar
cfr.setTimeZone(TimeZone.getTimeZone("Europe/Paris"))
// A calendar at GMT+0
val cutc = new GregorianCalendar
cutc.setTimeZone(TimeZone.getTimeZone("UTC"))
// Computes the time difference between the two time zones for a given date
def diff(year: Int, month: Int, day: Int) = {
cfr.clear
cutc.clear
cfr.set(year, month, day)
cutc.set(year, month, day)
cfr.getTimeInMillis - cutc.getTimeInMillis
}
diff(1970, JANUARY, 1) // Yields -3600000 => OK
diff(2000, AUGUST, 1) // Yields -7200000 => OK (daylight savings)
diff(1910, JANUARY, 1) // Yields -561000, or 9 minutes 21 seconds => HUH?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment