Java Day Convert To day2doy(int year, int month, int mday)

Here you can find the source of day2doy(int year, int month, int mday)

Description

Convert Day of Month to Day of Year.

License

Apache License

Parameter

Parameter Description
year Year.
month Month.
mday Day of month.

Return

Day of year.

Declaration

public static int day2doy(int year, int month, int mday) 

Method Source Code

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

public class Main {
    /** Convert Day of Month to Day of Year.
     * @param year Year./*from w  ww. jav a  2  s . c o  m*/
     * @param month Month.
     * @param mday Day of month.
     * @return Day of year.
     */
    public static int day2doy(int year, int month, int mday) {
        int[] regu_month_day = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
        int[] leap_month_day = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };
        int yday = 0;

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

Related

  1. day2msec(int day)
  2. day2String(int dayofweek)
  3. daysToSecs(long days)
  4. daysToTicks(double x)