Here you can find the source of doy2month(int year, int doy)
Parameter | Description |
---|---|
year | Year. |
doy | Day of year. |
public static int doy2month(int year, int doy)
//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; } }