TL; DR
LocalDate.parse ( "13136", DateTimeFormatter.ofPattern ( "uuDDD" ) ).getMonthValue()
5
... for May 2013.
Ordinal, not Julian
Your use of the word "Julian" is technically incorrect, although common. It seems that people are embarrassed by the number of days (1-365 or 1-366) with the practice of counting the number of days that have passed since January 1, 4713 BC is used in some scientific fields.
The terms "ordinal date" or day of the year are clearer.
ISO 8601
Your format for ordinal dates is not standard. If possible, use the standard ISO 8601 formats:
java.time
The modern way is the java.time classes, which supersede the nasty old obsolete time classes.
DateTimeFormatter
Note that the formatting pattern codes in the DateTimeFormatter class are similar to a legacy class, but not quite a few.
String input = "13136";
LocalDate
The LocalDate class represents a date value only without time and without a time zone.
LocalDate localDate = LocalDate.parse ( input, f );
Dump for the console.
System.out.println ("localDate: " + localDate );
localDate: 2013-05-16
Month
You can ask about the month of this LocalDate . The Month variable Month dozen objects, one for each month of the year. And unlike the crazy heritage classes, they are reasonably numbered 1-12 for January-December.
If you pass the month number around your code, I suggest that you pass these enumeration objects instead. This gives you the type of security, valid values, and self-documenting code.
Month month = localDate.getMonth();
If necessary, you can get the localized name of this month.
String output = month.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH );
If you really need the month number 1-12, ask anyway.
int monthNumber = month.getValue() ; int monthNumber = localDate.getMonthValue() ;
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
Where to get java.time classes?
- Java SE 8 and SE 9 and later
- Built in.
- Part of the standard Java API with integrated implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Most of the functionality of java.time is ported to Java 6 and 7 in ThreeTen-Backport .
- Android
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .