Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

default timezone and jsp/jakata ?

Status
Not open for further replies.

tick

Programmer
Jul 31, 2001
4
HK
Consider the following simple java app;

import java.util.*;

class wtfDate {

public static void main(String arguments[]){
TimeZone timeZone = TimeZone.getDefault();
System.out.println("TimeZone="+timeZone.getID());
}
}

when run on my australian based box i get;

TimeZone=Australia/Sydney

Which is what i expect.

But...

When i call this same code from jsp, ( in a java bean ) i get ;

TimeZone=EST

and any date/time info i produce from any calendar object i create afterwards is the wrong time.

I can force the timezone to the closer AET timezone and then things are ok, if not idea. ( not sure why i can't set the time zone to "Australia/Sydney", but AET seems ok for now.

The code i use to force in my bean is;

---------8<---------------
TimeZone timeZone = TimeZone.getTimeZone(&quot;AET&quot;);
cat.error(&quot;TimeZone=&quot;+timeZone.getID());

cal = Calendar.getInstance();
cal.setTimeZone(timeZone);
Date currentDate = cal.getTime();
cal.setTime(currentDate);

cat.error&quot;DAY_OF_MONTH : &quot;+cal.getCalendar.DAY_OF_MONTH));
cat.error(&quot;HOUR : &quot;+cal.get(Calendar.HOUR));
---------8<---------------

Incidently, i'm using log4j in my jsp app, and its date/time stamps are also set at the EST time zone.

Does anyone know what is causing this behaviour, and how it can be fixed at configuration level, rather than forcing from within the code.

Maybe i'm misunderstanding the use of timezone and/or calendar objects, if so, please enlighten me.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top