Calling forOffsetHours returns a time zone with a fixed offset, as per the documentation. A fixed offset of 6 hours is not equivalent to CST, which has DST rules and other historical transitions. There isn't any API in Joda-Time which returns time zones which match a given offset because it would return many of them.
Ron Olson wrote: > Hi all- > > I assume I'm doing something wrong here, but I've been going through > the docs and haven't come up with a reason why this should be > happening. > > Basically, if I create a new DateTime object and pass it a > DateTimeZone instance called from forOffsetHours(), when I try to > print the time using the DateTimeFormatter, I get -06:00 instead of > CST. Below is an example: > > import org.joda.time.DateTime; > import org.joda.time.DateTimeZone; > > import org.joda.time.format.DateTimeFormat; > import org.joda.time.format.DateTimeFormatter; > > public class TimeTest > { > public static void main(String[] args) > { > DateTime dt = new DateTime(); > DateTimeFormatter calendarTimeFormat = > DateTimeFormat.forPattern("hh:mm a z"); > System.out.println(dt.toString() + " - " + > calendarTimeFormat.print(dt)); > > Integer timeZoneOffset = -6; > > // And put them together > DateTime birthDateTime = new DateTime( 2004, > 12, > > 27, > > 16, > > 44, > > 0, > > 0, > > DateTimeZone.forOffsetHours(timeZoneOffset)); > > System.out.println(birthDateTime.toString() + " - " + > calendarTimeFormat.print(birthDateTime)); > } > > } > > This will print (as of a couple of minutes ago): > > 2008-11-22T23:06:27.399-06:00 - 11:06 PM CST > 2004-12-27T16:44:30.533-06:00 - 04:44 PM -06:00 > > > Might anyone have an idea why this is happening? Any help would be > appreciated. > > Ron > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Joda-interest mailing list > Joda-interest@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/joda-interest > > ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Joda-interest mailing list Joda-interest@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/joda-interest