From: Matthew H. <mh...@us...> - 2012-01-17 20:06:28
|
Hello, I use ICU4J to format dates. I've found some strange behavior when formatting a Date from a Calendar, when the Calendar is a java.util.Calendar not a com.ibm.icu.util.Calendar. For example, the code below formats a java.util.Calendar set to January 1, 1900. When the default time zone happens to be "Europe/Helsinki" it prints out "December 31, 1899 11:39:52 PM GMT+01:39:52". I expect it to print "January 1, 1900 12:00:00 AM GMT+02:00". java.util.Calendar c = java.util.Calendar.getInstance(); c.set( 1900, 0, 1, 0, 0, 0 ); c.set( java.util.Calendar.MILLISECOND, 0 ); System.out.println( "java.util.Calendar's time is " + c.getTime() ); com.ibm.icu.text.DateFormat df = com.ibm.icu.text.DateFormat.getDateTimeInstance( com.ibm.icu.text.DateFormat.LONG, com.ibm.icu.text.DateFormat.LONG ); System.out.println( "the formatted time is " + df.format( c.getTime() ) ); The problem disappears if I add TimeZone.setDefaultTimeZoneType( TimeZone.TIMEZONE_JDK ); at the beginning of my program. Is that the correct solution? Is there another solution that doesn't have such a global impact? Thanks for your time, Matt |