Java Month doy2month(int year, int doy)

Here you can find the source of doy2month(int year, int doy)

Description

Compute the month from day of year.

License

Apache License

Parameter

Parameter Description
year Year.
doy Day of year.

Return

Month.

Declaration

public static int doy2month(int year, int doy) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /** Compute the month from day of year. From GPS Toolkit code.
     * @param year Year./*from  w w  w  .  ja va 2s . com*/
     * @param doy Day of year.
     * @return Month.
     */
    public static int doy2month(int year, int doy) {
        int[] regu_month_day = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
        int[] leap_month_day = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
        int yday = 0;

        int month = 0;
        int mday = 0;

        int guess = (int) (doy * 0.032);
        int more = 0;

        // check for leap year
        if ((year % 4) == 0) {
            if ((doy - leap_month_day[guess + 1]) > 0)
                more = 1;
            month = guess + more + 1;
            mday = doy - leap_month_day[guess + more];
        } else {
            if ((doy - regu_month_day[guess + 1]) > 0)
                more = 1;
            month = guess + more + 1;
            mday = doy - regu_month_day[guess + more];
        }
        return month;
    }
}

Related

  1. checkMonth(int month)
  2. createDateMonth(String dateYear)
  3. createTestCCMonth()
  4. daemonThread(Runnable runnable)
  5. displayMonthlyPeriod(String week)
  6. extractMonthFromDate(String dateString)
  7. findMonth(String strMonth)
  8. fixMonth(int month)
  9. fixMonth(String m)