zoukankan      html  css  js  c++  java
  • python 日历(calendar)模块

    日历(Calendar)模块

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

    星期一是默认的每周第一天,星期天是默认的最后一天。

    更改设置需调用calendar.setfirstweekday()函数。模块包含了以下内置函数:

    序号函数及描述
    1 calendar.calendar(year,w=2,l=1,c=6)
    返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。 每日宽度间隔为w字符。每行长度为21* W+18+2* C。l是每星期行数。
    2 calendar.firstweekday( )
    返回当前每周起始日期的设置。默认情况下,首次载入caendar模块时返回0,即星期一。
    3 calendar.isleap(year)
    是闰年返回True,否则为false。
    4 calendar.leapdays(y1,y2)
    返回在Y1,Y2两年之间的闰年总数。
    5 calendar.month(year,month,w=2,l=1)
    返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7* w+6。l是每星期的行数。
    6 calendar.monthcalendar(year,month)
    返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。
    7 calendar.monthrange(year,month)
    返回两个整数。第一个是该月的星期几的日期码,第二个是该月的日期码。日从0(星期一)到6(星期日);月从1到12。
    8 calendar.prcal(year,w=2,l=1,c=6)
    相当于 print calendar.calendar(year,w,l,c).
    9 calendar.prmonth(year,month,w=2,l=1)
    相当于 print calendar.calendar(year,w,l,c)。
    10 calendar.setfirstweekday(weekday)
    设置每周的起始日期码。0(星期一)到6(星期日)。
    11 calendar.timegm(tupletime)
    和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍(1970纪元后经过的浮点秒数)。
    12 calendar.weekday(year,month,day)
    返回给定日期的日期码。0(星期一)到6(星期日)。月份为 1(一月) 到 12(12月)。

    简单实现指定日期日历

    代码实现

    # 导入日历模块
    import calendar
    # 输入指定年份
    yy = int(input('请输入年份:'))
    # 输入指定月份
    mm = int(input('请输入月份:'))
    # 打印日历
    print(calendar.month(yy, mm))

    执行结果

    请输入年份:2018
    请输入月份:12
       December 2018
    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
    31

     calendar 还有很多其他功能参数,此处只是简单实现打印指定日期日历。

  • 相关阅读:
    解析excel表格为DataSet
    easyui 上传文件代码
    上传文件后台代码
    easyui dialog
    C++ 强制设置文件大小
    std::function与std::bind
    glog 编译报错 ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail.
    Qt删除目录
    C++11 中的std::function和std::bind
    TortoiseGit 使用教程
  • 原文地址:https://www.cnblogs.com/bigtreei/p/8341908.html
Copyright © 2011-2022 走看看