In [1]:
import calendar
import datetime
In [2]:
dt = datetime.datetime(2019, 1, 1, 10, 10, 10)
print(dt)
In [3]:
print(calendar.isleap(dt.year))
In [4]:
d = datetime.date(2020, 1, 1)
print(d)
In [5]:
print(calendar.isleap(d.year))
In [6]:
def isleap_datetime(dt):
return calendar.isleap(dt.year)
In [7]:
print(dt)
In [8]:
print(isleap_datetime(dt))
In [9]:
print(d)
In [10]:
print(isleap_datetime(d))
In [11]:
def isleap_datetime2(dt):
return dt.year % 4 == 0 and (dt.year % 100 != 0 or dt.year % 400 == 0)
In [12]:
print(dt)
In [13]:
print(isleap_datetime2(dt))
In [14]:
print(d)
In [15]:
print(isleap_datetime2(d))