1. 程式人生 > >Python3-筆記-E-004-庫-日歷calendar

Python3-筆記-E-004-庫-日歷calendar

mtime == esc iter mic rdate idt num pan

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