Java Day Of Year dayOfYear(int year, int month, int day)

Here you can find the source of dayOfYear(int year, int month, int day)

Description

Gets day number in year

License

Apache License

Parameter

Parameter Description
year Year
month Month
day Day

Return

Day number in year

Declaration

public static int dayOfYear(int year, int month, int day) 

Method Source Code

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

public class Main {
    /**//from  ww w  . ja  v  a 2 s .  co m
     * Gets day number in year
     * 
     * @param year Year
     * @param month Month
     * @param day Day
     * @return Day number in year
     */
    public static int dayOfYear(int year, int month, int day) {
        int K = (isLeapYear(year)) ? 1 : 2;
        int N = (int) ((int) ((275 * month) / 9) - K * (int) ((month + 9) / 12) + day - 30);
        return N;
    }

    /**
     * Cheks is leap year or not
     * 
     * @param year Year value
     * @return True if leap year, false otherwise
     */
    public static boolean isLeapYear(int year) {
        if (year < 1582) {
            if (year % 4 == 0)
                return true;
        }
        if (year % 100 == 0 && (year / 100) % 4 != 0)
            return false;
        if (year % 4 == 0)
            return true;
        return false;
    }
}

Related

  1. dateOfYearBetween(final int month, final int dayOfMonth, final int fromMonth, final int fromDayOfMonth, final int toMonth, final int toDayOfMonth)
  2. dayOfYear(final int year, final int month, final int day)
  3. dayOfYear(int month, int day, int year)
  4. dayOfYear(int year, int month, int date)
  5. dayOfYear(int year, int month, int day)
  6. daysInPriorYears(final int y)
  7. daysInPriorYears(int yr)
  8. daysInPriorYears(int yr, boolean use1904windowing)
  9. daysInYear(int yearInteger)