Logo

Programming-Idioms

# 342 Leap year?
Determine if the current year is a leap year.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
final thisYear = DateTime.now().year;
final isLeap = DateTime(year, 2, 29).month == 2;
SysUtils
if IsLeapYear(SomeYear) then writeln('SomeYear is a leap year')
import calendar
import datetime
if calendar.isleap(datetime.date.today().year):
    print('This year is a leap year.')
require 'date'
Date.leap?( Date.today.year )
let leap_year = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);