how to convert a simple python code weekday check
Okay, i wrote this code myself awhile ago
but now im开发者_运维技巧 having trouble conerting it so it only does this years dates, ie the user would only have to type MM-DD instead of YYYY-MM-DD because we are going to assume its 2011
import datetime
def weekday(dateinput):
a = dateinput.split("-")
b = datetime.date(datetime.date.today().year, int(a[0]), int(a[1]))
c = b.strftime("%A")
return c
#- test harness: do not modify -#
dateinput = raw_input('Enter a date ("MM-DD"): ')
print "That's a " + weekday(dateinput) + '.'
If you actually want to assume 2011 even in 2012, replace datetime.date.today().year
with the hard-coded year.
import datetime
def weekday(dateinput):
dateinput = "2011-" + dateinput
a = dateinput.split("-")
b = datetime.date(int(a[0]), int(a[1]), int(a[2]))
c = b.strftime("%A")
return c
print weekday("03-15")
prints Tuesday
精彩评论