用Python写的日历

编程入门 行业动态 更新时间:2024-10-23 04:37:33

用Python写的<a href=https://www.elefans.com/category/jswz/34/1771006.html style=日历"/>

用Python写的日历

博客搬家了,最近同时更新,没准什么时候就完全搬走了-_-
这个是新博客地址,希望大家多多关照

#!/usr/bin/python2#It's my first Python programimport time#get date 获取当前日期
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 - 1if week == -1:week = 6#judge leap 判断是否是闰年
if year % 4 == 0 and year % 400 != 0 or year % 400 == 0 :isLeap = True
else :isLeap = False#all Day这个月一共有多少天
if month == '01' or month == '03' or month == '05' or month == '07' or month == '08' or month == '10' or month == '12' :allDay = 31
elif month == '02' and isLeap :allDay = 29
elif month == '02' and not isLeap :allDay = 28
else :allDay = 30#print CAL  输出这个月的日历
print '            ' + str(year) + '   ' + str(month)
print ''
print 'Sun  Mon  Tue  Wed  Thu  Fri  Sat'for i in range(week) :   #print space   输出空白部分print '    ',for i in range(1, allDay + 1) :   #print everday  输出日期x = str(i)print '%-4s' % x,week = week + 1if week == 7 :week = 0printraw_input()

更多推荐

用Python写的日历

本文发布于:2024-03-13 16:34:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1734393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日历   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!