English 中文(简体)
The API Joda-Time(java) doesnt respect the ISO 8601: bug or feature?
原标题:

According to their website, the class DUration implements the ISO 8601

http://en.wikipedia.org/wiki/ISO_8601#Durations

But let see an example. It is a duration of 14min & 51sec. In ISO 8601 those code are equivalent :

    PT14M51S
    PT891S
    System.out.println("bug "+new Duration("PT14M51S"));
     System.out.println("NO bug "+new Duration("PT891S");

The PT14M51S is a real extract for a postgresql database & correct. The joda-time api just convert everything in sec why ?It seems to dont know anything elese than the keyletter S(theres Y, M, D...)

Thanks in advance

问题回答

You need:

System.out.println("bug "+new Period("PT14M51S"));

To clarify, Joda uses "Period" to mean what everybody else calls "Duration" (ISO and Oasis for sure) and adds "Duration" to mean something similar but different. Yes, its really confusing.





相关问题
Jodatime - Custom Chronology

I would like to calculate a duration whereas 1 day will consist of 8 hours. Is creating a new Chronology is the right approach ? I did try to create a custom Chronology and override the assemble ...

Can I parse relative times with JodaTime?

I d love to be able to parse relative strings like now and yesterday and get JodaTime DateTimes. Is it possible? DateTimeFormat.forPattern and doesn t seem to support English relative times and I don ...

How to query a date in HQL (Hibernate) with Joda Time?

I am sure that someone familiar with HQL (I am myself a newbie) can easily answer this question. In my Grails application, I have the following domain class. class Book { org.joda.time.DateTime ...

Joda Time gives wrong time zone

I m using the Joda time (1.6) libraries and it keeps returning DateTime objects with the wrong time zone, British Summer Time instead of GMT. My Windows workstation (running JDK 1.6.0_16) thinks it s ...

Jodatime : what is there to keep up to date?

I read (dont t know where anymore, but see here) when using Jodatime you have to keep files up to date. What kind of files? Why is that?

热门标签