Consistency and simplicity. The time zone offset in the date format never correctly describes a time zone, except in the one special case: 'Z'. If this case was handled specially, then it might also be described as "unexpected". Constructing a DateTime by String is limited anyhow, and you'll have much more precise control by using a DateTimeFormatter of your choice. With it, you can call withOffsetParsed to preserve the time zone offset.

On 2010-03-31 06:56 AM, Bridges, Ed (Citco) wrote:

It's my understanding from ISO8601 that when you include a trailing 'Z' in a string form of a date/time that that indicates the timezone as UTC.

However when giving a string of this form to Joda, it instead converts it to local timezone unless you force it to UTC:

import org.joda.time.DateTime;

import org.joda.time.DateTimeZone;

public class JodaDateTimeZone {

    // example date from ISO spec:

    // http://dotat.at/tmp/ISO_8601-2004_E.pdf

    private static final String UTC_DATE = "1985-04-12T10:15:30Z";

    public static void main(String[] args) {

        DateTime dateTime = new DateTime(UTC_DATE);

        System.out.println(dateTime.toString());

        dateTime = new DateTime(UTC_DATE, DateTimeZone.UTC);

        System.out.println(dateTime.toString());

    }

}

Can someone explain the rationale behind this unexpected behavior?

Thanks,

Ed

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to