python日历查询系统_python不能导入模块

python日历查询系统_python不能导入模块pythoncalendar日历模块常用函数_pythoncalendar

1、calendar.calendar(year,w=2,l=1,c=6):返回year年年历

返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。
在这里插入图片描述

2、calendar.firstweekday( ):返回当前每周起始日期的设置。

默认情况下,首次载入 calendar 模块时返回 0,即星期一。

3、calendar.setfirstweekday(weekday):设置每周的起始日期码
import calendar c0 = calendar.firstweekday() # 输出:0 calendar.setfirstweekday(1) # 设置周一为1 c1 = calendar.firstweekday() # 输出:1 
4、 calendar.isleap(year) :闰年返回 True,否则为 False。
print(calendar.isleap(2022)) # False 
5、 calendar.leapdays(y1,y2) :返回在Y1,Y2两年之间的闰年总数
print(calendar.leapdays(2000,2022)) # 6 
6、calendar.month(year,month,w=2,l=1):返回year年month月日历

返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7* w+6。l是每星期的行数。

print(calendar.month(2022, 9, w=2, l=1)) 

输出:
在这里插入图片描述

7、 calendar.monthcalendar(year,month)

返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。

print(calendar.monthcalendar(2022,9)) 输出: [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 0, 0]] 
8、calendar.monthrange(year,month)—返回(month月第一天是星期几,month月天数)

返回的是一个元组数据(两个整数)。
第一个整数:代表本月起始星期数(0:星期一 … 6:星期天)
第二个整数:代表本月最后一天的日期数,即该月天数

print(calendar.month(2022, 9)) print(calendar.monthrange(2022, 9)) # (3, 30) 输出: September 2022 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 (3, 30) 
9、calendar.monthlen( year , month ):返回month 月天数
print(calendar.monthlen(2022,9)) # 30 
10、calendar.weekday(year,month,day):返回给定日期的日期码。

0(星期一)到6(星期日)。

print(calendar.month(2022, 9)) # 输出2022-9-30号对应的日期码 print(calendar.weekday(2022,9,30)) # 4  输出: September 2022 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 4 
11、calendar.prevmonth(year, month):返回month的上一个月year, month-1)
12、calendar.nextmonth(year, month):返回month的下一个月(year, month+1)
print(calendar.prevmonth(2022, 1)) # (2021, 12) print(calendar.prevmonth(2022, 4)) # (2022, 3)  print(calendar.nextmonth(2022, 12)) # (2023, 1) print(calendar.nextmonth(2022, 9)) # (2022, 10) 

今天的文章
python日历查询系统_python不能导入模块分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/60297.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注