用Python写的日历

博主分享了关于使用Python进行日历编程的经验,介绍了如何创建和管理日历,并提供了新博客的地址以供读者获取更多相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

#!/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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值