xs = [9999, 12, 31, 23, 59, 59]
import datetime
def time_stamp(t):
return datetime.datetime(*t).timestamp()
def get_days(y, m, d):
def is_leap(year):
return (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)
D1 = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]
D2 = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]
days = 0
for a in range(1970, y):
days += 365
if is_leap(a):
days += 1
days += D2[m - 1] if is_leap(y) else D1[m - 1]
days += d
return days
def unix(arr):
y, m, d, h, mn, s = arr
days = get_days(y, m, d)
return (((days * 24 + h) * 60) + mn) * 60 + s - 86400
r = unix(xs)
print(r, time_stamp(xs))
To embed this program on your website, copy the following code and paste it into your website's HTML: