You call getMonthOfYear() - it just returns an int . What value could he return a month earlier than October , which will satisfy you? In other words, let me take the Joda Time out of the equation ... what do you expect from the conclusion of this?
int month = 9; System.out.println(" Month : " + month);
?
You need to understand the difference between the data (the whole in this case) and the textual representation you want for this whole. If you need a specific format, I suggest you use DateTimeFormatter . (It is very rare that you need to print one field at a time ... I would expect you to want something like "2013-09-08" as a single line.)
You can also use String.format to control the output format, or DecimalFormat or DecimalFormat — there are many ways to format integers. You need to understand that the number 9 is just the number 9, but it does not have a format associated with it.
Jon skeet
source share