Implementing a simple calendar with Python
Read the current time and display this month's calendar
Output formatting
#!/usr/bin/python2
#It ' s my
Import time
#get date Gets the current day
Year = Time.strftime ('%Y ', Time.localtime (Time.time ()))
Year = (int) (year)
month = time.strftime ('%m ', Time.localtime (Time.time ()))
Day = Time.strftime ('%d ', Time.localtime (Time.time ()))
Day = (int) (day)
Week = Time.strftime ('%w ', Time.localtime (Time.time ()))
Week = (int) (week)
For I in range (0, day-1):
Week = Week-1
If week = = 1:
Week = 6
#judge leap to determine whether it is a leap year
If year% 4 = 0 and year%!= 0 or Year% 400 = 0:
Isleap = True
else:
Isleap = False
#all Day How many days are there in this month?
If month = = ' ' or ' month = = ' or month = ' ' or ' month = ' ' or ' month = = ' 12 ' or month = = ' ":
AllDay = 31
Elif month = = ' ' and isleap:
AllDay = 29
Elif month = = ' ' And not isleap:
AllDay = 28
else:
AllDay = 30
#print CAL to output this month's calendar
print ' + str (year) + ' + str (month)
print '
print ' Sun Mon Tue Wed Thu Fri Sat '
For I in Range (week): #print spaces output Blank part
print ',
For I in range (1, AllDay + 1): #print everday Output Date
x = str (i)
print '%-4s '% x,
Week = week + 1
If week = 7:
Week = 0
Print
Raw_input ()