码迷,mamicode.com
首页 > 编程语言 > 详细

Python3-笔记-E-004-库-日历calendar

时间:2017-10-26 11:45:11      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:...   ext   完整   lis   import   with   boolean   参数   soft   

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缩写名称
 
 
 

Python3-笔记-E-004-库-日历calendar

标签:...   ext   完整   lis   import   with   boolean   参数   soft   

原文地址:http://www.cnblogs.com/vito13/p/7735609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!