Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #342 Leap year?

Determine if the current year is a leap year.

import static java.lang.Integer.parseInt;
import static java.lang.System.currentTimeMillis;
int y = parseInt("%tY".formatted(currentTimeMillis()));
boolean b = y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
import java.time.Year;
boolean b = Year.now().isLeap();
final thisYear = DateTime.now().year;
final isLeap = DateTime(year, 2, 29).month == 2;

2, 29 will become 3, 1 in non-leap years.

New implementation...
< >
steenslag