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

Setting default locale changes timezone for DateFormat

XMLWordPrintable

    • 1.1.8
    • generic, x86, sparc
    • generic, solaris_2.6, windows_95
    • Verified



        Name: rlT66838 Date: 07/16/97


        Run the following Java applet. Notice that the
        time zone for the applet is the German time
        zone, not that of the virtual machine. Changing
        the locale in the program to en_US changes the
        timezone to PST.

        I'm executing this with the 1.1.3 appletviewer.

        import java.text.*;
        import java.awt.*;
        import java.applet.*;
        import java.util.*;



        // Test Java locale-sensitive date formatting on output

        public class TestDateFormat extends Applet {
           Date curDate;
           DateFormat shortdate, fulldate;
           String strShortDate, strFullDate;
           public void init () {
              Locale curLocale = new Locale("de","DE");
              Locale.setDefault(curLocale);
              curDate = new Date();
              shortdate = DateFormat.getDateInstance(DateFormat.SHORT);
              fulldate = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG
        );
              strShortDate = new String("The current date (short form) is " + shortdate.
        format(curDate));
              strFullDate = new String("The current date (long form) is " + fulldate.for
        mat(curDate));
           }

           public void paint(Graphics g) {
                 g.setColor(Color.black);
                 g.drawString(strShortDate,10,10);
                 g.drawString(strFullDate,10,30);
           }
        }

        The HTML file is:
        <HTML>
        <HEAD>
        <TITLE> Testing DateFormat </TITLE>
        </HEAD>
        <BODY>
        This is the applet:<P>
        <applet code="TestDateFormat.class" width=500 height=300>
        <param name=Language value="de">
        <param name=Territory value="DE">
        </applet>
        </BODY>
        </HTML>

        ======================================================================
        ###@###.### - 1997-11-19 :
        Related to this bug report is the following report
        (Incident 20513, Bug 0129 on BetaSphere). I tested
        the code with JDK1.2beta2 (1.2U) and found that the
        bug is still reproducible. I think it should really
        be fixed before JDK1.2 goes fcs next year, otherwise
        international acceptance of Java is needlessly jeopardized.

        SYNOPSIS : Incorrect timezone is reported when data converted by DateFormat.
        DESCRIPTION : There is a bug with timezone printed in date format (Win95).
        I have timezone GMT+6 but DateFormat displays time as tz = GMT+2
        and allign time according to it. Date.toString() displays
        correct timezone.

        Sample program:

        import java.text.*;
        import java.util.*;

        public class test_tz
        {
          public static void main(String aa[])
          {
            Date date = new Date();
            System.out.println(date);
            System.out.println(DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG).format(date));
          }
        }

        ======================================================================

              aliusunw Alan Liu (Inactive)
              rlewis Roger Lewis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: