Logo

Programming-Idioms

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

Idiom #342 Leap year?

Determine if the current year is a leap year.

y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)
import calendar
import datetime
if calendar.isleap(datetime.date.today().year):
    print('This year is a leap year.')
from datetime import date
from calendar import isleap
y = date.today().year
isleap(y)
final thisYear = DateTime.now().year;
final isLeap = DateTime(year, 2, 29).month == 2;
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();
SysUtils
if IsLeapYear(SomeYear) then writeln('SomeYear is a leap year')
require 'date'
Date.leap?( Date.today.year )
let leap_year = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);

New implementation...
< >
steenslag