Share

Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





Java - Code Samples

 Sample 1. Code Sample / Example / Snippet of java.time.Month

    public static LocalDate ofYearDay(int year, int dayOfYear) {

YEAR.checkValidValue(year);

DAY_OF_YEAR.checkValidValue(dayOfYear);

boolean leap = IsoChronology.INSTANCE.isLeapYear(year);

if (dayOfYear == 366 && leap == false) {

throw new DateTimeException("Invalid date 'DayOfYear 366' as '" + year + "' is not a leap year");

}

Month moy = Month.of((dayOfYear - 1) / 31 + 1);

int monthEnd = moy.firstDayOfYear(leap) + moy.length(leap) - 1;

if (dayOfYear > monthEnd) {

moy = moy.plus(1);

}

int dom = dayOfYear - moy.firstDayOfYear(leap) + 1;

return new LocalDate(year, moy.getValue(), dom);

}


   Like      Feedback      java.time.Month



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus