分类: Python/Ruby
2005-10-22 21:36:49
今天花一个多小时写了一个小函数.用来到得由昨天日期组成的字符串.
如果没有20个月的儿子在一边捣蛋,可能会快一些.
import time
def before_today():
result = time.strftime("%Y%m%d")
year1 = time.strftime("%Y")
month1 = time.strftime("%m")
day1 = time.strftime("%d")
td = int(day1) - 1
ty = int(year1)
tm = int(month1)
if td == 0:
tm = tm - 1
if str(tm) in ("1","3","5","7","8","10"):
td = 31
elif str(tm) in ("4","6","9"):
td = 30
elif tm == 0:
td = 31
tm = 12
ty = ty - 1
elif tm == 2:
if (ty % 4 == 0 and ty % 100 <> 0) or (ty % 400 == 0):
print "is RunNian"
td = 29
else:
print "Not RunNian"
td = 28
if tm < 10:
month1 = "0" + str(tm)
else:
month1 = str(tm)
if td < 10:
day1 = "0" + str(td)
else:
day1 = str(td)
result = str(ty) + month1 + day1
print result
return result
print before_today()
今天感觉程序的调试排错方面好像不太好.