0

Actually I'm trying to use the joda time library to manipulate dates. It seems preety good, but I've found a non-plus-ultra wall.

I have a jodatime period that I want to converto to days. So, if my period has 1 year, 1 month, 1 week and 1 day, total should be: 365 + 30 (or 30 or 28 or 29) + 7 + 1 = 403 days aprox.

But, If I try

int total= myPeriod.edadHombre.toStandardDays().getDays();

...it throws an exception. What I'm doing wrong? Is "toStandardDays" the right way to obtain the total amount of days in a jodatime period?

aprados
  • 374
  • 4
  • 16

1 Answers1

1

While I try to understand why doesn't work, I've found another way to do it:

//I take a date (myDate) to create a start point and an end date:
DateTime startDate =new DateTime(myDate);
DateTime endDate = new DateTime();  //now()

Days someDays= Days.daysBetween(startDate, endDate);
int result=someDays.getDays();

That's all. Anyway, I hope that somebody give me an answer about toStandardDays...

aprados
  • 374
  • 4
  • 16
  • 1
    Well, just look at the [documentation](http://www.joda.org/joda-time/apidocs/org/joda/time/Period.html#toStandardDays--). There it is clearly stated that the method will throw an exception if the period also contains years or months. – Meno Hochschild Dec 15 '14 at 16:10
  • Ouch! I didn't see it. I was in a hurry. Thank you! – aprados Dec 15 '14 at 18:05