Find day of week from month and year

Paul McGuire ptmcg at
Sat Sep 3 16:27:48 CEST 2005


You didn't look closely enough at those results.  The OP's point was
that he did not know how to set all the tuple values correctly.  Here's
a clearer example, I think:

import time
print time.asctime((2005,9,1,0,0,0,0,0,0))
print time.asctime((2005,9,1,0,0,0,1,0,0))
print time.asctime((2005,9,1,0,0,0,2,0,0))
print time.asctime((2005,9,1,0,0,0,3,0,0))

Mon Sep 01 00:00:00 2005
Tue Sep 01 00:00:00 2005
Wed Sep 01 00:00:00 2005
Thu Sep 01 00:00:00 2005

No matter what time zone you're in, Sep 1, 2005 can't be all those days
of the week! :)

Your code works because you use mktime, which appears to ignore the
dayOfWeek element of the input tuple, as shown by the following:

print time.asctime(time.gmtime(time.mktime((2005,9,1,0,0,0,0,0,0))))
print time.asctime(time.gmtime(time.mktime((2005,9,1,0,0,0,1,0,0))))
print time.asctime(time.gmtime(time.mktime((2005,9,1,0,0,0,2,0,0))))
print time.asctime(time.gmtime(time.mktime((2005,9,1,0,0,0,3,0,0))))

Thu Sep 01 06:00:00 2005
Thu Sep 01 06:00:00 2005
Thu Sep 01 06:00:00 2005
Thu Sep 01 06:00:00 2005

-- Paul

More information about the Python-list mailing list