____tz_zs

日历模块 calendar

calendar 模块中,周一到周日用 0 到 6 表示。
源码如下所示

(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)

calendar.calendar

calendar.calendar()
以一个多行字符串格式返回指定的年的日历
参数

  • w = 每个日期之间的间隔字符数
  • l = 每周所占用的行数
  • c = 每个月之间的间隔字符数

# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import calendarcal = calendar.calendar(theyear=2018, w=2, l=1, c=6, m=3)
print(type(cal))
print(cal)
"""
<class 'str'>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
"""

calendar.month

calendar.month() 获取某年某月的月日历字符串
格式:calendar.month(年,月)
返回值:月日历的字符串

# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import calendarm3 = calendar.month(theyear=2018, themonth=3)
print(m3)
"""March 2018
Mo Tu We Th Fr Sa Su1  2  3  45  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 31
"""

calendar.monthcalendar

calendar.monthcalendar() 返回某年某月的月日历矩阵,每行代表一周
格式:calendar.monthcalendar(年,月)
返回值:矩阵
注意:矩阵中没有天数用0表示

# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import calendarm = calendar.monthcalendar(year=2018, month=3)
print(type(m))
print(m)
"""
<class 'list'>
[[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, 31, 0]]
"""

calendar.monthrange

calendar.monthrange() 返回指定月份第一天(即1号)的星期日期,和本月的总天数
格式:calendar.monthrange(年,月)
回值:元组(int 1号是周几,int 总天数)
注意:日历一周默认为 0 -6 表示周一到周天

# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import calendarw, t = calendar.monthrange(year=2019, month=1)
print(w)
print(t)
"""
1
31
"""

应用
获取指定月的一点和最后一天

# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import calendar
from datetime import datetime
from datetime import datew, t = calendar.monthrange(year=2019, month=1)
# 获取指定月的一点和最后一天
firstDay = datetime(year=2019, month=1, day=1)  # <type 'datetime.datetime'>
lastDay = datetime(year=2019, month=1, day=t)
print(firstDay)
print(lastDay)
"""
2019-01-01 00:00:00
2019-01-31 00:00:00
"""
firstDay = date(year=2019, month=1, day=1)  # <type 'datetime.date'>
lastDay = date(year=2019, month=1, day=t)
print(firstDay)
print(lastDay)
"""
2019-01-01
2019-01-31
"""

calendar.weekday

calendar.weekday() 返回指定日期所对应的星期日期
格式:calendar.weekday(年,月,日)
返回值:0(周一)~ 6(周日)

# -*- coding: utf-8 -*-
"""
@author: tz_zs
"""
import calendarw = calendar.weekday(year=2019, month=1, day=24)
print(w)
"""
3
"""

Python 日历模块 calendar相关推荐

  1. python日历节日表_python日历模块_Python日历模块| calendar()方法与示例

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

  2. c linux time微秒_Python时间处理模块:time模块、datetime模块及日历模块Calendar

    无论是那一个开发语言进行开发,时间的处理都是非常重要的,正确的处理时间是一个程序员开发中必备的技能,特别是对时间精度要求比较高,或者是要分清楚本地时间和服务器时间的这些业务要求,今天就来讲一讲Pyth ...

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

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

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

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

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

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

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

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

  7. python之模块calendar(汇集了日历相关的操作)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #calendar日历模块import calendar#3个大类: calendar.Calendar(fi ...

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

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

  9. python日历模块_python 日历模块calendar

    calendar #打印2019年的日历 x= calendar.calendar(2019) print(x) #打印全年日历 calendar.prcal(2019) # 打印月份 c = cal ...

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

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

最新文章

  1. 系统发生 1219 错误。 提供的凭据与已存在的凭据集冲突。
  2. 腾讯信息流平台产品负责人牛津:个性化推荐的那些事儿
  3. MapReduce Job本地提交过程源码跟踪及分析
  4. 蔡高厅老师 - 高等数学阅读笔记 - 10 - 函数图像的描绘 - 微分三角形 -曲率(44 ~48)
  5. 检测手机用户安装的应用程序是否有使用某权限
  6. vue 项目中常见的几个问题
  7. 《HBase权威指南》读书笔记4
  8. 梅特勒托利多xk3124电子秤说明书_托利多电子秤设置说明书1
  9. 贾俊平统计学思维导图- 第九章 分类数据分析
  10. centos yum 国内源
  11. 使用matlab代码计算太阳高度角
  12. C语言-基础入门-学习笔记(13):结构体
  13. 数据分析可视化08 案例 2:历史数据变化趋势图设计
  14. 微软时间服务器同步错误,Windows Server 设置时间同步出错问题
  15. python实现中国象棋
  16. 48种数据分析可视化图表
  17. Android Studio超级详细安装教程(AMD)
  18. 经典车间生产调度问题模型及其算法 目录
  19. 企业微信个人二维码在哪里?会失效吗?
  20. 大一大学计算机导论论文,大学计算机导论论文3500字_大学计算机导论毕业论文范文模板.doc...

热门文章

  1. 嵌入式面试常见问题(七)—各大公司面试题
  2. 【C语言编程练习】20050. 计算存款利息
  3. Apache 服务器特点
  4. 什么是关联分析?如何利用关联规则做好数据挖掘
  5. Vue脚手架安装详解
  6. Opencv项目实战:09 物体尺寸测量
  7. 辞职信微信html,女教师辞职信走红微信背后:“走心”
  8. CSS绝对定位absolute详解
  9. python如何进行md5解密_python写一个md5解密器
  10. [html+css+js] 小米官网首页制作