Wednesday, January 9, 2008

Epic year

Epoch time starts from 1970. Given a date in YYYY-MM-DD, list all dates that evaluates to 1970. For example, 2005-11-24 = 1970.

In python:
[(yyyy,mm,dd) 
    for dd in range(1,31) 
    for mm in range(1,12) 
    for yyyy in range(1970+1+1,1970+12+31) 
        if time.localtime(time.mktime((yyyy,mm,dd,0,0,0,0,0,0)))[:3] == (yyyy,mm,dd) 
            and yyyy-mm-dd == 1970]

So, 1970+12+31 = 2013

No comments:

Post a Comment