Get the correct TimeZone on DateFormatTag(s): Date and Time

There is a bug in the DateFormat/SimpleDateFormat classes. We must set the TimeZone manually.
System.out.println("Good TimeZone from Calendar : " +
          Calendar.getInstance().getTimeZone().getID());
DateFormat df = DateFormat.getDateInstance();
System.out.println("Bad TimeZone from DateFormat : " +
          df.getTimeZone().getID());
//  fix the TimeZone          
df.setCalendar(Calendar.getInstance());
System.out.println("Good TimeZone from DateFormat : " +
df.getTimeZone.getID());



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2011
[ home ]