3 Replies Latest reply on Nov 5, 2007 5:29 PM by 807603

    specific time in different timezones

    807603
      Hello all,

      I have the following scenario. My developement pc is in a PDT timezone and my server is in a EDT timezone. Plus, the date entries in the server need to be GMT values.

      I know that, right now at least, there are 3 hours of difference between PDT and EDT, and 4 hours of difference between EDT and GMT.
              Calendar calendar = Calendar.getInstance();
              SimpleDateFormat timeDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss, z");
      
              Date date = calendar.getTime();
      
              System.out.println("server:\t" + timeDateFormat.format(date));
              timeDateFormat.setTimeZone(TimeZone.getTimeZone("EST5EDT"));
              System.out.println("local:\t" + timeDateFormat.format(date));
              timeDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
              System.out.println("GMT:\t" + timeDateFormat.format(date));
      output:
      server:     2007-11-02 11:15:43, PDT
      local:     2007-11-02 14:15:43, EDT
      GMT:     2007-11-02 18:15:43, GMT

      Now, I need to convert today's midnight time (EDT) to GMT from my pc having PDT timezone.
              SimpleDateFormat timeDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss, z");
      
              String today = "2007-11-02 00:00:00, EST5EDT";
              Date date = timeDateFormat.parse(today);
      
              System.out.println("server:\t" + timeDateFormat.format(date));
              timeDateFormat.setTimeZone(TimeZone.getTimeZone("PST8PDT"));
              System.out.println("local:\t" + timeDateFormat.format(date));
              timeDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
              System.out.println("GMT\t" + timeDateFormat.format(date));
      output:
      server:     2007-11-02 00:00:00, EST
      local:     2007-11-01 22:00:00, PDT
      GMT:     2007-11-02 05:00:00, GMT

      1. Why does it show EST instead of EST5EDT or just EDT?
      2. Why there are now 2 hours of difference between EDT (EST) and PDT? I think it's related to 1.

      I'm pulling my hair out of my head with this one. I'd really appreciate any comments on this. Thanks
        • 1. Re: specific time in different timezones
          807603
          Today Nov 5th, my code is working fine. My problem is obviously related to the daylight saving time. Since I seem to be using a recent Java Platform (1.5.0_11), does this mean that DST are not fully supported by SimpleDateFormat?
          • 2. Re: specific time in different timezones
            807603
            I don't know if this applies to you or not, but you might want to take a look at this article:
            http://java.sun.com/javase/timezones/
            • 3. Re: specific time in different timezones
              807603
              fun1asma wrote:
              Today Nov 5th, my code is working fine. My problem is obviously related to the daylight saving time. Since I seem to be using a recent Java Platform (1.5.0_11), does this mean that DST are not fully supported by SimpleDateFormat?
              As far as I know, Java 1.5.0_11 supports the TZ rules in the U.S. as they exist now. It's possible that there's a bug in that support. It may also be that Java is using your OS's notion of TZs and your OS may not be up to date. I forget the exact rules as to when Java uses its own TZ rules vs. those of the OS.