此模块的函数都是日历相关的,例如打印某月的字符月历。

星期一是默认的每周第一天,星期天是默认的最后一天。更改设置需调用  calendar.setfirstweekday()  函数。模块包含了以下内置函数:

1. calendar.calendar( year, w=2 ,l=1,c=6)

返回一个多行字符串格式的  year 年年历,3 个月一行,间隔距离为c。 每日宽度间隔为w字符。每行长度为21* W+18+2* C。l是每星期行数。

>>> print( calendar.calendar(2018))2018January                   February                   March
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su1  2  3  4  5  6  7                1  2  3  4                1  2  3  48  9 10 11 12 13 14       5  6  7  8  9 10 11       5  6  7  8  9 10 11
15 16 17 18 19 20 21      12 13 14 15 16 17 18      12 13 14 15 16 17 18
22 23 24 25 26 27 28      19 20 21 22 23 24 25      19 20 21 22 23 24 25
29 30 31                  26 27 28                  26 27 28 29 30 31April                      May                       June
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su1          1  2  3  4  5  6                   1  2  32  3  4  5  6  7  8       7  8  9 10 11 12 13       4  5  6  7  8  9 109 10 11 12 13 14 15      14 15 16 17 18 19 20      11 12 13 14 15 16 17
16 17 18 19 20 21 22      21 22 23 24 25 26 27      18 19 20 21 22 23 24
23 24 25 26 27 28 29      28 29 30 31               25 26 27 28 29 30
30July                     August                  September
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su1             1  2  3  4  5                      1  22  3  4  5  6  7  8       6  7  8  9 10 11 12       3  4  5  6  7  8  99 10 11 12 13 14 15      13 14 15 16 17 18 19      10 11 12 13 14 15 16
16 17 18 19 20 21 22      20 21 22 23 24 25 26      17 18 19 20 21 22 23
23 24 25 26 27 28 29      27 28 29 30 31            24 25 26 27 28 29 30
30 31October                   November                  December
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su1  2  3  4  5  6  7                1  2  3  4                      1  28  9 10 11 12 13 14       5  6  7  8  9 10 11       3  4  5  6  7  8  9
15 16 17 18 19 20 21      12 13 14 15 16 17 18      10 11 12 13 14 15 16
22 23 24 25 26 27 28      19 20 21 22 23 24 25      17 18 19 20 21 22 23
29 30 31                  26 27 28 29 30            24 25 26 27 28 29 3031

2. calendar.firstweekday()

返回当前每周起始日期的设置。默认情况下,首次载入caendar模块时返回0,即星期一

3. calendar.setfirstweekday(weekday)

设置每周的起始日期码。0(星期一)到6(星期日)。

4. calendar.month(year,month,w=2,l=1)

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

>>> import  calendar
>>>
>>> calendar.firstweekday()
0
>>>
>>>
>>> print(calendar.month(2018,9))September 2018
Mo Tu We Th Fr Sa Su1  23  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>>>
>>> calendar.setfirstweekday(6)
>>>
>>> calendar.firstweekday()
6
>>>
>>> print( calendar.month(2018,9))September 2018
Su Mo Tu We Th Fr Sa12  3  4  5  6  7  89 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

5. calendar.isleap(year)

是闰年返回True,否则为false。

>>> import  calendar
>>>
>>> calendar.isleap(2018)
False
>>>
>>> calendar.isleap(2020)
True

6. calendar.leapdays(y1,y2)

返回在Y1,Y2两年之间的闰年总数。

>>> import calendar
>>>
>>> calendar.leapdays(2018,2020)
0
>>>
>>> calendar.leapdays(2018,2021)
1
>>> calendar.leapdays(2016,2021)
2
>>>
>>> calendar.leapdays(2016,2020)
1
>>> calendar.leapdays(1000,2000)
242

7. calendar.monthcalendar(year,month)

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

>>> import  calendar
>>>
>>> print(calendar.monthcalendar(2018,9))
[[0, 0, 0, 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, 0, 0, 0, 0]]

8. calendar.monthrange(year,month)

返回两个整数。第一个是该月的星期几,第二个是该月有几天。星期几是从0(星期一)到 6(星期日)。

>>> import  calendar
>>>
>>> calendar.monthrange(2018,9)
(5, 30)

9. calendar.prcal(year,w=2,l=1,c=6)

相当于 print calendar.calendar(year,w,l,c).

10. calendar.prmonth(year,month,w=2,l=1)

相当于 print calendar.calendar(year,w,l,c)。

>>> import calendar
>>>
>>> calendar.prmonth(2018,9)September 2018
Su Mo Tu We Th Fr Sa12  3  4  5  6  7  89 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

11. calendar.timegm(tupletime)

和 time.gmtime 相反:接受一个时间元组形式,返回该时刻的时间辍(1970纪元后经过的浮点秒数)。

12. calendar.weekday(year,month,day)

返回给定日期的日期码。0(星期一)到6(星期日)。月份为 1(一月) 到 12(12月)。

>>> import calendar
>>>
>>> calendar.weekday(2018,9,16)
6

Python——日历模块相关推荐

  1. python日历模块_Python日历模块| firstweekday()方法与示例

    python日历模块 Python calendar.firstweekday()方法 (Python calendar.firstweekday() Method) firstweekday() m ...

  2. python日历模块_Python日历模块| prmonth()方法与示例

    python日历模块 Python calendar.prmonth()方法 (Python calendar.prmonth() Method) prmonth() method is an inb ...

  3. python日历模块_Python日历模块| setfirstweekday()方法与示例

    python日历模块 Python calendar.setfirstweekday()方法 (Python calendar.setfirstweekday() Method) setfirstwe ...

  4. python实现日历功能_详解Python日历模块的使用

    calendar模块的函数都是日历相关的,提供了对日期的一些操作方法,和生成日历的方法. calendar模块中提供了三大类: 一.calendar.Calendar(firstweekday=0) ...

  5. Python日历模块| weekheader()方法与示例

    Python calendar.weekheader()方法 (Python calendar.weekheader() Method) weekheader() method is an inbui ...

  6. python中weekday_[转载] Python日历模块| 使用示例的weekday()方法

    参考链接: Python中的日历函数 2(monthrange(),prcal(),weekday()-) Python calendar.weekday()方法 (Python calendar.w ...

  7. [转载] Python日历模块| 使用示例的weekday()方法

    参考链接: Python中的日历函数 2(monthrange(),prcal(),weekday()-) Python calendar.weekday()方法 (Python calendar.w ...

  8. Python日历模块| 使用示例的weekday()方法

    Python calendar.weekday()方法 (Python calendar.weekday() Method) weekday() method is an inbuilt method ...

  9. python日历模块提示没有属性月_Python calendar日历模块的说明

    calendar(日历)模块,默认每周第一天是星期一,最后一天是星期天. 函数及描述 1. calendar.calendar(year, w=2, l=1, c=6, m=3) 返回一个多行字符串格 ...

  10. python日历模块_Python calendar日历模块的说明

    calendar(日历)模块,默认每周第一天是星期一,最后一天是星期天. 函数及描述 1. calendar.calendar(year, w=2, l=1, c=6, m=3) 返回一个多行字符串格 ...

最新文章

  1. 笔记:编程的一些建议 - 时间伙伴 - 博客园
  2. SpringCloud Config 分布式配置
  3. 使用Lucid Virtu在有独立显卡的情况下使用Intel硬件加速H.264编码
  4. 以太坊geth区块链私链建立
  5. 用几何画板求曲线弧长的方法
  6. mysql as 后面字段,mysql 字段as详解及实例代码
  7. linux 常用图形库,在Linux下常用的3款Git图形客户端
  8. linux弹窗指令_Linux弹出U盘的正确姿势(命令行)
  9. java实现pdf旋转_Java实现PDF文本旋转倾斜的方法
  10. 推广的euclid_欧几里得(Euclid)与拓展的欧几里得算法
  11. 股票买卖原理_如何在智能手机上买卖股票
  12. Git教程及常用命令
  13. 大学生活质量指北,高考毕业生填报志愿参考必备
  14. 微信图片,此图片来自微信公众平台未经允许不可引用解决方案
  15. 统信UOS系统Redis-5.0.5安装包方式部署
  16. 代谢组学数据处理软件——NormalizeMets
  17. Ubuntu18.04/20.04复现算法RandLa-net 数据集S3DIS
  18. NS-3学习笔记(4)水声模块aqua-sim-ng模型及helper类内容解析
  19. word文档中公式和文字不等高
  20. vue更换网页上的标题(Vue-mete)

热门文章

  1. 量子计算机治愈癌症,如果量子计算机实现了,癌症可以治愈吗?
  2. C++到底还能做什么?
  3. Web前端技术基础实验报告二之格式化文本、段落与列表
  4. 第四次作业-微软必应词典客户端
  5. 知识图谱构建软件Protege下载使用
  6. IT项目管理画图题【太原理工大学】
  7. 【转载】番茄时钟解说
  8. Nature Microbiology:植物根系分泌物影响菌群结构
  9. 达梦数据库02-DM8客户端安装与数据迁移
  10. PHP 导出excel表格的3种方法