Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4035146

All dates display as PST regardless of TimeZone

XMLWordPrintable

    • x86
    • windows_95, windows_nt



      Name: mc57594 Date: 02/27/97


      import java.util.GregorianCalendar;
      import java.util.Calendar;
      import java.util.TimeZone;

      // set to GMT
      TimeZone thedefault = TimeZone.getTimeZone("GMT");
      TimeZone.setDefault(thedefault);

      // check to be sure... its GMT all right
      TimeZone testdefault = TimeZone.getDefault();
      String testtimezone = testdefault.getID();
      System.out.println("Test timezone = " + testtimezone);

      // now try to use the default GMT time zone
      GregorianCalendar greenwichcalendar =
          new GregorianCalendar(1997, 3, 4, 23, 0);
      // try anything to set hour to 23:00 !!!
      greenwichcalendar.set(Calendar.HOUR_OF_DAY, 23);
      // get time
      Date greenwichdate = greenwichcalendar.getTime();
      // try every format
      SimpleDateFormat dateformat =
          new SimpleDateFormat("MM/dd/yy HH:mm z");
      DateFormat fullformat =
          DateFormat.getDateTimeInstance(DateFormat.FULL,
                                         DateFormat.FULL);
      DateFormat longformat =
          DateFormat.getDateTimeInstance(DateFormat.LONG,
                                         DateFormat.LONG);
      DateFormat defaultformat =
          DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
                                         DateFormat.DEFAULT);
      DateFormat shortformat =
          DateFormat.getDateTimeInstance(DateFormat.SHORT,
                                         DateFormat.SHORT);
      // format every way
      String simplestring = dateformat.format(greenwichdate);
      String fullstring = fullformat.format(greenwichdate);
      String longstring = longformat.format(greenwichdate);
      String defaultstring = defaultformat.format(greenwichdate);
      String shortstring = shortformat.format(greenwichdate);
      // all output indicates PST... why???
      System.out.println("simple format: " + simplestring);
      System.out.println("full format: " + fullstring);
      System.out.println("long format: " + longstring);
      System.out.println("default format: " + defaultstring);
      System.out.println("short format: " + shortstring);

      company - MCI , email - ###@###.###
      ======================================================================

            ssenthilsunw Shanmugam Senthil (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: