zoukankan      html  css  js  c++  java
  • Python3-笔记-E-004-库-日历calendar

    import calendar
    import time

    calen_text = calendar.TextCalendar()
    # 打印月历
    calen_text.prmonth(2017, 5, w=0, l=0)
    # 打印年历
    calen_text.pryear(2017, w=2, l=1, c=6, m=3)

    '''
    日历相关的操作
    默认星期一作为一周的第一天, 可设置
    '''

    # === Calendar ===
    # Calendar(firstweekday=0) // Calendar对象 firstweekday:一周的第一天,0周一(默认),6周日
    calen = calendar.Calendar()


    calen_iter = calen.iterweekdays() # 迭代器,一周的星期数字 => 0 1 2 3 4 5 6
    calen_iter = calen.itermonthdates(2017, 5) # 迭代器, xx月中所有天 => 2017-05-01 2017-05-02 017-05-03 ...
    calen_iter = calen.itermonthdays2(2017, 5) # 迭代器, xx月中所有(,星期) => (1, 0) (2, 1) (3, 2) ...
    calen_iter = calen.itermonthdays(2017, 5) # 迭代器, xx月中的所有天 => 1 2 3 ...
    calen_iter = calen.monthdatescalendar(2017, 5) # 迭代器, xx月中data(,,)对象 => date(2017, 5, 1) date(2017, 5, 2) ...
    calen_iter = calen.monthdays2calendar(2017, 5) # 迭代器, xx月中(,星期)的周列表 => [(1, 0), (2, 1) ...] [ ... ] ...
    calen_iter = calen.monthdayscalendar(2017, 5) # 迭代器, xx月中日的周列表 => [1,2,3 ...] [...] ...
    calen_lists = calen.yeardatescalendar(2017, width=3) # x年所有data(,,)对象的月列表
    calen_lists = calen.yeardays2calendar(2017, width=3) # x年所有(,星期)的月列表
    calen_lists = calen.yeardayscalendar(2017, width=3) # x年所有日的月列表


    # === TextCalendar ===
    # TextCalendar(firstweekday=0) // 纯文本的日历
    calen_text = calendar.TextCalendar()

    calen_str = calen_text.formatmonth(2017, 5, w=0, l=0) # xx月所有日
    calen_text.prmonth(2017, 5, w=0, l=0) # (打印) xx月所有日
    calen_str = calen_text.formatyear(2017, w=2, l=1, c=6, m=3) # x年所有日
    calen_text.pryear(2017, w=2, l=1, c=6, m=3) # (打印) x年所有日

    # === HTMLCalendar ===
    # HTMLCalendar(firstweekday=0) // HTML的日历
    calen_html = calendar.HTMLCalendar()

    calen_str = calen_html.formatmonth(2017, 5, withyear=True) # xx月的所有日
    calen_str = calen_html.formatyear(2017, width=3) # x年所有日
    calen_str = calen_html.formatyearpage(2017, width=3, css='calendar.css', encoding=None) # (完整编码) x年所有日


    # === calendar 模块的函数 ===
    calendar.setfirstweekday(
    calendar.SUNDAY) # 设置每周开始的工作日(默认:0周一,6周日),如设置星期天为第一个工作日(calendar.SUNDAY) 参数:MONDAY / TUESDAY / WEDNESDAY / THURSDAY / FRIDAY / SATURDAY / SUNDAY
    num = calendar.firstweekday() # 返回每周的第一天的星期
    boolean = calendar.isleap(2017) # x年是否为闰年
    num = calendar.leapdays(2010, 2020) # x年到y年的闰年数
    num = calendar.weekday(2017, 5, 6) # xxx日的星期几
    strs = calendar.weekheader(1) # 星期E, 1为名字长度
    weekday, days = calendar.monthrange(2017, 5) # xx (星期, 月天数)
    calen_lists = calendar.monthcalendar(2017, 5) # xx月的月历
    calen_lists = calendar.prmonth(2017, 5, w=0, l=0) # xx月的日历
    calen_strs = calendar.month(2017, 5, w=0, l=0) # 月历
    calendar.prcal(2017, w=0, l=0, c=6, m=3) # (打印) 整年日历
    calen_strs = calendar.calendar(2017, w=2, l=1, c=6, m=3) # 整年日历
    time_s = calendar.timegm(time.gmtime(time.time())) # 时间元组 转为 时间戳

    calen_iter = calendar.day_name # 迭代器, 星期E名称
    calen_iter = calendar.day_abbr # 迭代器, 星期E缩写名称
    calen_iter = calendar.month_name # 迭代器, E名称
    calen_iter = calendar.month_abbr # 迭代器, E缩写名称
     
     
     
  • 相关阅读:
    十六.jQuery源码解析之Sizzle设计思路.htm
    关于微信浏览不能URL传参,URL中的问号被删除
    websocket 通信协议
    java_httpservice
    Socket.Io 做个标记 下来了解下
    通过netty实现服务端与客户端的长连接通讯,及心跳检测。
    NETTY 编码器介绍
    Netty4.0学习教程
    FORM表单不刷新提交POST数据
    Linux0.11学习
  • 原文地址:https://www.cnblogs.com/vito13/p/7735609.html
Copyright © 2011-2022 走看看