获取时间小技巧

  1. import datetime

  2. # 今天的日期

  3. today = datetime.date.today() #2020-01-03
  4. # 今天日期去掉年份

  5. str_today = str(today)[5:] #01-03
  6. # 判断今天是星期几

  7. weekday = datetime.datetime.strptime(str(today),'%Y-%m-%d').weekday() + 1 #结果:5
  8. # 获取明天日期

  9. tomorrow = timeToday + datetime.timedelta(days=1) #2020-01-04