我的python歷程--第二天


今天花一个多小时写了一个小函数.用来到得由昨天日期组成的字符串.
如果没有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