javacalendar

How to get month according to day of year


I have input like 34 which means its 3rd day of February, but how to determine programatically in Java by taking day of year and getting month name or month month value like 0 for January is there any API in Java that handles this. I searched in Calendar class but did not found any.


Solution

  •     Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_YEAR, 34);
        System.out.println(cal.get(Calendar.MONTH));
    

    Will return 1 (as Months start with 0).