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("AET"
cat.error("TimeZone="+timeZone.getID());
cal = Calendar.getInstance();
cal.setTimeZone(timeZone);
Date currentDate = cal.getTime();
cal.setTime(currentDate);
cat.error"DAY_OF_MONTH : "+cal.getCalendar.DAY_OF_MONTH));
cat.error("HOUR : "+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
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("AET"
cat.error("TimeZone="+timeZone.getID());
cal = Calendar.getInstance();
cal.setTimeZone(timeZone);
Date currentDate = cal.getTime();
cal.setTime(currentDate);
cat.error"DAY_OF_MONTH : "+cal.getCalendar.DAY_OF_MONTH));
cat.error("HOUR : "+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