Created
November 24, 2010 16:23
-
-
Save olim7t/713911 to your computer and use it in GitHub Desktop.
This file contains 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 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