• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange Age output using Joda time?

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've got
Age = P20Y
What do the 'P' and 'Y' stand for?
Thanks
Jack
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Luk wrote:
I've got
Age = P20Y
What do the 'P' and 'Y' stand for?
Thanks
Jack


Sorry, I know now year.getYear()
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15758
74
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API documentation of org.joda.time.Years.toString() answers your question: it returns the period as a string in ISO 8601 format, a standard format for representing dates, times, periods, etc.

"P20Y" in this format means a period of 20 years.
 
Stephen Colebourne
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use LocalDate, not DateMidnight. DateMidnight does not work well in some countries where midnight does not exist once a year due to daylight savings.

In addition, LocalDate has dedicated methods fromDateFields() and fromCalendarFields() to convert from java.util.Date and Calendar.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!