#usr/bin/python3
#! -*-conding : utf-8 -*- #2018.3.14
"""
日历(Calendar)模块
此模块的函数都是日历相关的,例如打印某月的字符月历。
星期一是默认的每周第一天,星期天是默认的最后一天。更改设置需调用calendar.setfirstweekday()函数。模块包含了以下内置函数:
"""
import time
import calendar #calendar.calendar(year,w=2,l=1,c=6)返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。 每日宽度间隔为w字符。每行长度为21* W+18+2* C。l是每星期行数。
print(calendar.calendar(2018,w=2,l=1,c=6)) #calendar.firstweekday( ) 返回当前每周起始日期的设置。默认情况下,首次载入caendar模块时返回0,即星期一。
print (calendar.firstweekday()) # calendar.isleap(year) 是闰年返回True,否则为false。
print(calendar.isleap(2016)) # calendar.leapdays(y1,y2) 返回在Y1,Y2两年之间的闰年总数
print(calendar.leapdays(1999,2018)) # calendar.month(year,month,w=2,l=1) 返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7* w+6。l是每星期的行数。
print (calendar.month(2018,3,w=2,l=1)) # calendar.monthcalendar(year,month) 返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。
print(calendar.monthcalendar(2018,3,)) # calendar.monthrange(year,month) 返回两个整数。第一个是该月的星期几的日期码,第二个是该月的日期码。日从0(星期一)到6(星期日);月从1到12。
print(calendar.monthrange(2018,4)) # calendar.prcal(year,w=2,l=1,c=6) 相当于 print calendar.calendar(year,w,l,c). # calendar.prmonth(year,month,w=2,l=1) 相当于 print calendar.calendar(year,w,l,c)。 # calendar.setfirstweekday(weekday) 设置每周的起始日期码。0(星期一)到6(星期日)。
print (calendar.setfirstweekday(5))
print (calendar.month(2018,3,w=2,l=1)) # calendar.timegm(tupletime) 和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍(1970纪元后经过的浮点秒数)。
print (calendar.timegm(time.localtime())) # calendar.weekday(year,month,day) 返回给定日期的日期码。0(星期一)到6(星期日)。月份为 1(一月) 到 12(12月)
print (calendar.weekday(2018,6,23)) #python中的calendar #返回指定年的某月
def get_month(year, month):
return calendar.month(year, month) #返回指定年的日历
def get_calendar(year):
return calendar.calendar(year) #判断某一年是否为闰年,如果是,返回True,如果不是,则返回False
def is_leap(year):
return calendar.isleap(year) #返回某个月的weekday的第一天和这个月的所有天数
def get_month_range(year, month):
return calendar.monthrange(year, month) #返回某个月以每一周为元素的序列
def get_month_calendar(year, month):
return calendar.monthcalendar(year, month) def main():
year = 2016
month = 11
test_month = get_month(year, month)
print(test_month)
print('#' * 50)
#print(get_calendar(year))
print('{0}这一年是否为闰年?:{1}'.format(year, is_leap(year)))
print(get_month_range(year, month))
print(get_month_calendar(year, month)) if __name__ == '__main__':
main()

日历(Calendar)模块的更多相关文章

  1. python日期与日历Datetime和Calendar模块

    datetime模块 1.1 概述 datetime比time高级了不少,可以理解为datetime基于time进行了封装,提供了更多的实用的函数,datetime的接口更加的直观,更容易调用 1.2 ...

  2. calendar模块

    calendar模块是个日历模块 1  判断是否是闰年 #!/urs/bin/evn python # -*- coding:utf-8 -*- import calendar print(calen ...

  3. #15 time&datetime&calendar模块

    前言 从这一节开始,记录一些常用的内置模块,模块的学习可能比较无聊,但基础就在这无聊的模块中,话不多说,本节记录和时间相关的模块! 一.time模块 Python中设计时间的模块有很多,但是最常用的就 ...

  4. python五十五课——calendar模块

    4.calendar模块: 构造:calendar(year,[w=2,l=1,c=6]):返回year年的完整的日历信息对象 和闰年相关的函数如下: isleap(year):判断year是否是闰年 ...

  5. calendar 模块

    calendar模块,即日历模块,提供了对日期的一些操作方法,和生成日历的方法 注:星期一是默认的每周第一天,星期天是默认的最后一天.更改设置需调用calendar.setfirstweekday() ...

  6. 小白学 Python(22):time 和 calendar 模块简单使用

    人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...

  7. python Calendar 模块导入及用法

    Calendar 是python 日历模块,此模块的函数都是日历相关的,例如打印某月的字符月历,星期之类的模块,下面剖析python Calendar 模块导入及用法. 1,python导入日历模块 ...

  8. python标准库-calendar 模块

    原文地址:http://www.bugingcode.com/blog/python_calendar.html calendar 模块是python实现的unix 的 cal命令.它可以以标准的模式 ...

  9. [习题]日历(Calendar)控件的障眼法(.Visible属性),使用时才出现?不用就消失?

    原文出處  http://www.dotblogs.com.tw/mis2000lab/archive/2013/09/02/calendar_icon_visible.aspx [习题]日历(Cal ...

  10. [习题]输入自己的生日(年/月/日)#2 -- 日历(Calendar)控件的时光跳跃,一次跳回五年、十年前?--TodaysDate属性、VisibleDate属性

    原文出處  http://www.dotblogs.com.tw/mis2000lab/archive/2013/06/10/calendar_visibledate_birthday_dropdow ...

随机推荐

  1. Gradle Goodness: Running Java Applications from External Dependency

    With Gradle we can execute Java applications using the JavaExec task or the javaexec() method. If we ...

  2. Java编码问题原因以及解决

    一.文件编码 Unicode 是首选编码.Unicode 是全球范围的字符编码标准. 小结: GBK 与unicode之间的转换是通过gbk unicode映射表. UTF-8 与unicode之间的 ...

  3. 利用binlog2sql闪回丢失数据

        today,i'll using the open source tool named "binlog2sql" which is release by danfengch ...

  4. 关于Hibernate基于version的乐观锁

    刚刚接触SSH框架,虽然可能这个框架已经比较过时了,但是个人认为,SSH作为一个成熟的框架,作为框架的入门还是可以的. 马马虎虎学完了Hibernate的基础,总结一点心得之类的. 学习Hiberna ...

  5. linux系统基础之六--系统引导(基于centos7.4 1708)

  6. webpack-dev-server 多入口自动刷新,支持对象

    万物的来源~webpack 本身 watch webpack watch 传送门 webpack 可以监听文件变化,当它们修改后会重新编译 watch boolean 启用 Watch 模式.这意味着 ...

  7. vue服务端渲染缓存应用

    vue缓存分为页面缓存.组建缓存.接口缓存,这里我主要说到了页面缓存和组建缓存 页面缓存: 在server.js中设置 const LRU = require('lru-cache') const m ...

  8. 【Spark】源码分析之RDD的生成及stage的切分

    一.概述 Spark源码整体的逻辑(spark1.3.1): 从saveAsTextFile()方法入手 -->saveAsTextFile()  --> saveAsHadoopFile ...

  9. ArrayList的源码分析(基于jdk1.8)

    1.初始化 transient Object[] elementData; //实际存储元素的数组 private static final Object[] DEFAULTCAPACITY_EMPT ...

  10. 【Hive三】Hive理论

    1. Hive基础 1. Hive基础 Hive基本概念 引入原因: Hive是什么 Hive数据管理 四种数据模型 Hive内部表和外部表 Hive数据类型 Hive的优化 Map的优化: Redu ...