On 10 May 2011 10:53, Mathieu Bolla <mathieu.bo...@gmail.com> wrote:
> Hi there,
>
> I'm writting a small piece of software that has to read and write dates as
> plain text on a webservice I don't own nor control.
>
> The format is:
> "EEE, dd MMM yyyy HH:mm:ss z"
>
> I can write the dates the way I want, but using the same exact pattern
> won't read it back.
>
> Here is a minimalist code to demonstrate the problem, using Joda 1.6.2:
>
> ---
> package utilities;
>
> import java.util.Locale;
>
> import org.joda.time.DateTime;
> import org.joda.time.DateTimeZone;
> import org.joda.time.format.DateTimeFormat;
> import org.joda.time.format.DateTimeFormatter;
>
> public class TimeFormats {
> private static final DateTimeFormatter formater =
> DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss
> z").withLocale(Locale.US);
> public static String format(DateTime date) {
> return formater.print(date);
> }
>
> public static DateTime parse(String string) {
> return formater.parseDateTime(string);
> }
> public static void main(String[] args) {
> DateTime date = new
> DateTime().withYear(2011).withMonthOfYear(5).withDayOfMonth(6).withHourOfDay(17).withMinuteOfHour(30).withSecondOfMinute(38).withMillisOfSecond(0).withZone(DateTimeZone.UTC);
> System.out.println(parse(format(date)));
> }
> }
> ---
>
> Has anyone an idea of what's going wrong? I can't find any clue on such a
> simple subject...
>
> Thank you for reading and helping...
>
> Mathieu Bolla
>
Hi,
AFAIK, joda-time can't parse the timezone. [1]
"*Zone names*: Time zone names ('z') cannot be parsed."
I don't know why that's the case; maybe someone else here can pitch in. I
recently had to use java.util.Date and friends to cope with this same issue.
For completeness, here is the stack trace that I think you're seeing:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid
format: "Fri, 06 May 2011 16:30:38 UTC" is malformed at "UTC"
at
org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:683)
at TimeFormats.parse(TimeFormats.java:17)
at TimeFormats.main(TimeFormats.java:24)
Cheers,
James
[1]
http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html
>
>
> ------------------------------------------------------------------------------
> Achieve unprecedented app performance and reliability
> What every C/C++ and Fortran developer should know.
> Learn how Intel has extended the reach of its next-generation tools
> to help boost performance applications - inlcuding clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> Joda-interest mailing list
> Joda-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>
------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest