import datetime import calendar #獲取當天日期值 currentdate = datetime.date.today() print(currentdate) year= currentdate.year month = currentdate.month day = currentdate.day print(year,month,day) print(calendar.weekday(year,month,day)) currentday =calendar.weekday(year,month,day) # 系統默認:星期一作為一周的第一天(即:0),星期日作為一周的最后一天(即:6) print(currentday) #判斷當天是周幾? if currentday == 0: print("當天為周一") elif currentday ==1: print("當天為周二") elif currentday ==2: print("當天為周三") elif currentday ==3: print("當天為周四") elif currentday == 4: print("當天為周五") elif currentday == 5: print("當天為周六") else: print("當天為周七") #判斷當天是否為周末 if currentday > 5: print("當天為周末") else: print("工作日") import time print(time.localtime()) # 打印當前時間是本年的第幾周 print(time.strftime("%W"))