calendar模块的主要功能是针对万年历、星期几的,此外模块内还有方便的判断闰年、获取月份名、星期名的方法

1、模块的类

1.1、calendar.Calendar([firstweekday])

四个获得生成器的函数:iterweekdays()、itermonthdates(year, month)、itermonthdays2(year, month)、itermonthdays(year, month),分别获得数字形式的星期几、某年某月的datetime.date对象、某年某月的日期号和对应星期几、某年某月的日期号
三个获得某年某月日期列表的函数:monthdatescalendar(year, month)、monthdays2calendar(year, month)、monthdayscalendar(year, month),分别返回datetime.date对象、数字形式的日期号和星期几、数字形式的日期号
三个获得某年日期列表的函数:yeardatescalendar(year[, width])、yeardays2calendar(year[, width])、yeardayscalendar(year[, width]),分别返回datetime.date对象、数字形式的日期号和星期几、数字形式的日期号
都会将不在本月里的日期号标为0

1.2、calendar.TextCalendar([firstweekday])

格式化的日历,以一个多行字符串存储:formatmonth(theyear, themonth[, w[, l]])、formatyear(theyear[, w[, l[, c[, m]]]])
直接print格式化的日历,函数返回None:prmonth(theyear, themonth[, w[, l]])、pryear(theyear[, w[, l[, c[, m]]]])
w 控制月份内列宽,l 控制行宽,c 控制月份间宽度,m 控制总列数

1.3、calendar.HTMLCalendar([firstweekday])

返回HTML表的函数:formatmonth(theyear, themonth[, withyear])、formatyear(theyear[, width])
直接返回整个HTML页面代码:formatyearpage(theyear[, width[, css[, encoding]]])

2、模块的方法(函数)

setfirstweekday(weekday):指定一周的起始,星期一为0
firstweekday():返回设置的起始
isleap(year):判断是否为闰年
leapdays(y1, y2):统计y1和y2间共几个闰年,包括y1和y2
weekday(year, month, day):判断某天是星期几
weekheader(n):返回包含所有星期几的缩写的一个字符串,从设置的起始开始,n控制每个缩写的长度,3以后添加空格
monthrange(year, month):返回包含某年某月日期起始的元组
monthcalendar(year, month):返回二维列表
prmonth(theyear, themonth[, w[, l]]):同TextCalendar.prmonth()
month(theyear, themonth[, w[, l]]):同TextCalendar.formatmonth()
prcal(year[, w[, l[c]]]):同TextCalendar.pryear()
calendar(year[, w[, l[c]]]):同TextCalendar.formatyear()

3、模块的属性

day_name、day_abbr、month_name、month_abbr:星期几的全称、缩写、月份的全称、缩写,以实例形式存储,可以遍历获得其中的值

Python2.7-canlendar的更多相关文章

  1. 让VIM支持Python2 by update-alternatives

    前言  Ubuntu 16+中$ sudo apt install vim所安装的vim只支持Python3,但很多插件如YCM和powerline均需要Python2,那就来场"生命贵在折 ...

  2. 烂泥:python2.7和python3.5源码安装

    本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我的微信ilanniweb 前几天在centos6.6安装ansible时,一直提示python版本不对,导致不能安 ...

  3. python版本随意切换之python2.7+django1.8.7+uwsgi+nginx源码包部署。

    资源准备: wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz wget https://www.djangoproject ...

  4. windows XP上实现python2.7.5和python3.4.3共存

    windows XP上实现python2.7.5和python3.4.3共存过程记录: 1. 首先安装python2.7.5和python3.4.3,两个版本安装顺序不分前后; 2. 检查系统环境变量 ...

  5. Python2 基本数据结构源码解析

    Python2 基本数据结构源码解析 Contents 0x00. Preface 0x01. PyObject 0x01. PyIntObject 0x02. PyFloatObject 0x04. ...

  6. Ubuntu安装Python2.7,nodejs

    安装Python2.7 sudo add-apt-repository ppa:fkrull/deadsnakes-python2.7sudo apt-get update sudo apt-get ...

  7. Windows下安装python2和python3双版本

    现在大家常用的桌面操作系统有:Windows.Mac OS.ubuntu,其中Mac OS 和 ubuntu上都会自带python.这里我们只介绍下Windows(我用的Win10)环境下的pytho ...

  8. [python]CentOS 6下安装Python2.7

    安装方法 如果在CentOS上自己编译安装过python2.7,使用过程中会发现有些标准库没有安装之类的问题. 逛别人博客的时候发现,一个便捷的方法:使用RHSCL的全称是Red Hat Softwa ...

  9. 在CentOS 6.5上安装python2.7

    1.yum groupinstall “Development tools” 2.安装编译Python需要的组件 yum install zlib-devel bzip2-devel openssl- ...

  10. python2不同版本安装json模块

    1.常用json库主要有json-py和simplejson 1) json-py 包含json和minjson,用法一样 Python (#, Jan , ::) [GCC (Red Hat -)] ...

随机推荐

  1. Spring全家桶系列–SpringBoot渐入佳境

    //本文作者:cuifuan //本文将收录到菜单栏:<Spring全家桶>专栏中 首发地址:https://www.javazhiyin.com/20913.html 萌新:小哥,我在实 ...

  2. Springboot — 用更优雅的方式发HTTP请求(RestTemplate详解)

    RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率. 我之前的HTTP开发是用ap ...

  3. python基础训练题1-列表操作

    1,在列表末尾添加一个值 >>> l = [ 10, 20 ] >>> l [10, 20] >>> l.append( 'ghostwu' ) ...

  4. HDU4417(SummerTrainingDay08-N 主席树)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. Codeforces485D(SummerTrainingDay01-K)

    D. Maximum Value time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...

  6. JavaScript判断值是否是NaN

    第一种方法: if (!Number.isNaN) { Number.isNaN = function (n) { return ( typeof n === 'number' && ...

  7. org.springframework.beans.factory.BeanDefinitionStoreException Invalid bean defi

    org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 's ...

  8. 设计模式原则(7)--Composition&AggregationPrinciple(CARP)--合成&聚合复用原则

    作者QQ:1095737364    QQ群:123300273     欢迎加入! 1.定义:  要尽量使用合成和聚合,尽量不要使用继承. 2.使用场景: 要正确的选择合成/复用和继承,必须透彻地理 ...

  9. (二)收集的MongoDB命令集合

    一:针对整个数据库的 1."show dbs" 命令可以显示所有数据的列表. 2. "db" 命令可以显示当前数据库对象或集合. 3."use&quo ...

  10. 自定义data-*

    HTML5的自定义属性data-*详细介绍和JS操作实例 < div id="user" data-id="123456" data-name=" ...