Java LocalDate Calculate doy(LocalDate date)

Here you can find the source of doy(LocalDate date)

Description

Finds the day-of-year of the date.

License

Open Source License

Parameter

Parameter Description
date the date to query

Return

the day-of-year

Declaration

static int doy(LocalDate date) 

Method Source Code

//package com.java2s;
/**// w  w w.j  a  v  a  2  s  .c om
 * Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */

import java.time.LocalDate;

public class Main {
    private static final int[] STANDARD = { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
    private static final int[] LEAP = { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 };

    /**
     * Finds the day-of-year of the date.
     * <p>
     * Faster than the JDK method.
     * 
     * @param date  the date to query
     * @return the day-of-year
     */
    static int doy(LocalDate date) {
        int[] lookup = (date.isLeapYear() ? LEAP : STANDARD);
        return lookup[date.getMonthValue()] + date.getDayOfMonth();
    }
}

Related

  1. convertDatabaseDateToUS(LocalDate databaseDate)
  2. converterToLocalDate(final String date)
  3. convertLocalDateToDatabaseDateString(LocalDate localDate)
  4. dateToSystemLocalDate(Date d)
  5. daysAgo(LocalDate pastDate)
  6. fastDateWrite(LocalDate localDate)
  7. fastDateWriteWeeks(LocalDate localDate)
  8. getAge(LocalDate birthday)
  9. getAge(LocalDate birthDay)