JDK-4065244 : TimeZone NightMare.... The movie...
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.1.1,1.1.3
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1997-07-17
  • Updated: 1997-10-23
  • Resolved: 1997-10-23
Related Reports
Duplicate :  
Description

Name: rlT66838			Date: 07/16/97


HI,

We are currently coding an application using timezone
and I have some problem with the time zone return by java.util.Date

On Solarix 2.5.1, if I do a 


	import java.util.Date;

	class tt
	{	
	public static void main(String args[])
		throws java.text.ParseException
	{
		Date d;

		d = new Date();

		double tz;
		tz = d.getTimezoneOffset();

		System.out.println(tz+" mins");
		System.out.println((tz/60.0)+" hours\n");

		System.out.println(d.toString());
		System.out.println(d.toGMTString());
	}
	}


----------------------------------
If I run is from Linkoping, Sweden: (jdk1.1.1 same result for 1.1.2)

Sweden  <262> r
-210.0 mins
-3.5 hours
Wed Jul 16 10:34:56 GMT+03:30 1997
16 Jul 1997 08:04:56 GMT

Sweden <261> date ; date -u
Wed Jul 16 09:04:54 MET DST 1997
Wed Jul 16 07:04:54 GMT 1997
	
----------------------------------
And now if I run it from Montreal, Canada: (jdk1.1.3)

[Montreal 3:03] <75> r
240.0 mins
4.0 hours
Wed Jul 16 00:03:30 PDT 1997
16 Jul 1997 08:03:30 GMT

[Montreal 3:03] <75> date;date -u
Wed Jul 16 03:03:39 EDT 1997
Wed Jul 16 07:03:39 GMT 1997

----------------------------------

And againg, from Melbourn, Australia (jdk 1.1.?)
Australia> java tt
240.0mins
4.0 hours
Wed Jul 16 00:05:35 PDT 1997
16 Jul 1997 08:05:35 GMT

Australia > date;date -u
Wed Jul 16 17:05:52 EST 1997
Wed Jul 16 07:05:52 GMT 1997
----------------------------------

This is really a nightmare,  I don't know what is the problem!
Am I using the java in a wrong way?
Is there something I should set before running the program?

This is REALLY IMPORTANT FOR US. We have to deliver for testing
an application at the end of July!  


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

roger.lewis@Eng 1997-07-28

The time returned from calendar and date is not Middle European Time (MET) but always PDT that is not one of the defined tome zones in TimeZone

I was no able to get the current time/date/timezone, but
always ended up with the "PDT" timezone and my time (MET) -9 hours that
match with the time in California.

This is the sample code that I tried out to try to get the MET
time:


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.SimpleTimeZone;
import java.io.*;


public class MyDate
{
  
  public  MyDate()
    {
      
    }
  
  public void printUsingDate()
    {
      String newName="Date : ";
      SimpleDateFormat formatter
	= new SimpleDateFormat ("yyyy:MM:dd:HH:mm:ss:z");
      Date currentTime_1 = new Date();
      String dateString = formatter.format(currentTime_1);
      newName=newName.concat(dateString);
      System.out.println("Using date: "+newName);
    }
  

  public void printUsingCalendar()
    {
      
      String newName="Calendar : ";
       SimpleDateFormat formatter
	= new SimpleDateFormat ("yyyy:MM:dd:HH:mm:ss:z");

      
      TimeZone tz=TimeZone.getDefault();
      
      GregorianCalendar cal=new  GregorianCalendar(tz);
      
      Date currentTime_1 = cal.getTime();
      String dateString = formatter.format(currentTime_1);
      newName=newName.concat(dateString);
      System.out.println("Using calendar : "+newName);
	
    }

  public void printUsingSimpleTimeZone()
    {
      
      String newName="Calendar : ";
      SimpleDateFormat formatter
	= new SimpleDateFormat ("yyyy:MM:dd:HH:mm:ss:z");

      SimpleTimeZone tz=new SimpleTimeZone(-8,"MET");
      
      GregorianCalendar cal=new  GregorianCalendar(tz);
      
      Date currentTime_1 = cal.getTime();
      String dateString = formatter.format(currentTime_1);
      newName=newName.concat(dateString);
      System.out.println("Using simple date zone: "+newName);
	
    }

  public void ids()
    {
      
      String[] ids;
      ids=TimeZone.getAvailableIDs();
      
      for (int i=0;i<ids.length;i++)
      {
	System.out.println(" Time zone: "+ids[i]);
      }
    }


  
  public static void main(String[] args) 
    {
      System.out.println(" Date");
      MyDate date = new MyDate();
      date.ids();
      date.printUsingDate();
      date.printUsingCalendar();
      date.printUsingSimpleTimeZone();
      
  }
}

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

Comments
WORK AROUND Name: rlT66838 Date: 07/16/97 The only work around I see it to use c++!!! ======================================================================
11-06-2004