最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python 命令行日历 获取时间 格式化输出
时间:2022-06-25 04:42:04 编辑:袖梨 来源:一聚教程网
使用 Python 实现简单日历
读取当前时间并显示本月日历
输出格式化
#!/usr/bin/python2
#It's my first Python program
import 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 - 1
if 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 + 1
if week == 7 :
week = 0
print
raw_input()
相关文章
- 女神漫画免费阅读在线观看最新版本下载安装-女神漫画全集高清完整版免费漫画入口页面 02-10
- 豆包网页版官方入口-豆包AI人工智能在线体验 02-10
- 成何体统电视剧32集全集:高清在线观看(免下载直达) 02-10
- 学科网登录入口-中小学学科网官网电脑版 02-10
- QQ网页版扫码登录入口-QQ网页版文件传输入口 02-10
- 一耽女孩免费漫画阅读软件下载安装手机版-一耽女孩正版免费下载安卓入口 02-10