I think I've found the answer. Due to an amazingly silly feature of the TimeZone API which returns a GMT timezone for invalid timezone ids (not null or exception as you'd expect) ... i didn't notice that the correct timezone id should have been "GB-Eire" and not "GB/Eire". Sorry... Joe. On 4/17/07, Joe Desbonnet <joe@xxxxxxxxxx> wrote:
Just when I thought I really understood the Java time API this test case below threw me today. Same results with the current FC6 Java stack (up to date) and Sun JDK (1.5.0_07). Why oh why is 17:00 UK/Irish local time the same as 17:00 UTC ? The local time should be one hour ahead due to daylight savings.? Funny - I wrote lots of code last year relating to logging sensor data and I had no problems normalizing the timestamps to UTC. Now I just can seem to do it. A bug in Java timezone files or my brain? import java.util.Date; import java.util.TimeZone; import java.text.SimpleDateFormat; public class DateTest { public static void main (String arg[]) throws Exception { TimeZone localTz = TimeZone.getTimeZone ("GB/Eire"); SimpleDateFormat localDateFormat = new SimpleDateFormat ("yyyyMMdd HH:mm:ss"); localDateFormat.setTimeZone(localTz); TimeZone utcTz = TimeZone.getTimeZone ("UTC"); SimpleDateFormat utcDateFormat = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); utcDateFormat.setTimeZone(utcTz); String datetime = "20070417 17:00:00"; Date d1 = localDateFormat.parse(datetime); Date d2 = utcDateFormat.parse(datetime); if (d1.getTime() == d2.getTime()) { System.err.println ("Error: GB/Eire = UTC + Daylight Savings (ie d1-d2 = 1 hour, not 0 hour)"); } } }
-- fedora-devel-java-list mailing list fedora-devel-java-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/fedora-devel-java-list