monthdays2calendar(year, month)
返回指定年和月的所有日期,把日期和第几周组成元组。
例子:
#python 3.4
import calendar
cal = calendar.Calendar(0)
for i in cal.monthdays2calendar(2015, 11):
print(i)
print(';')
结果输出如下:
[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 6)]
;
[(2, 0), (3, 1), (4, 2), (5, 3), (6, 4), (7, 5), (8, 6)]
;
[(9, 0), (10, 1), (11, 2), (12, 3), (13, 4), (14, 5), (15, 6)]
;
[(16, 0), (17, 1), (18, 2), (19, 3), (20, 4), (21, 5), (22, 6)]
;
[(23, 0), (24, 1), (25, 2), (26, 3), (27, 4), (28, 5), (29, 6)]
;
[(30, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6)]
;
monthdayscalendar(year, month)
按一周来返回指定年和月的日历。
例子:
#python 3.4
import calendar
cal = calendar.Calendar(0)
for i in cal.monthdayscalendar(2015, 11):
print(i)
print(';')
结果输出如下:
[0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0]
;
yeardatescalendar(year, width=3)
返回一年里所有日期,并且按月按同排列。
例子:
#python 3.4
import calendar
cal = calendar.Calendar(0)
for i in cal.yeardatescalendar(2015, 10):
print(i)
print(';')
结果输出如下:
[[[datetime.date(2014, 12, 29), datetime.date(2014, 12, 30), datetime.date(2014, 12, 31), datetime.date(2015, 1, 1), datetime.date(2015, 1, 2), datetime.date(2015, 1, 3),
...
datetime.date(2015, 12, 27)], [datetime.date(2015, 12, 28), datetime.date(2015, 12, 29), datetime.date(2015, 12, 30), datetime.date(2015, 12, 31), datetime.date(2016, 1, 1), datetime.date(2016, 1, 2), datetime.date(2016, 1, 3)]]]
;
yeardays2calendar(year, width=3)
返回指定年的所有日期,日期和一周第几天组成元组形式。
例子:
#python 3.4
import calendar
cal = calendar.Calendar(0)
for i in cal.yeardays2calendar(2015, 10):
print(i)
print(';')
结果输出如下:
[[[(0, 0), (0, 1), (0, 2), (1, 3), (2, 4), (3, 5), (4, 6)], [(5, 0), (6, 1), (7, 2), (8, 3), (9, 4), (10, 5), (11, 6)],
...
, (30, 2), (31, 3), (0, 4), (0, 5), (0, 6)]]]
;
yeardayscalendar(year, width=3)
返回指定年的所有日期,每周组成一个列表,当不存在这个月以
例子:
#python 3.4
import calendar
cal = calendar.TextCalendar(0)
print(cal.formatmonth(2015, 11))
print(cal.formatmonth(2015, 11, w = 5))
print(cal.formatmonth(2015, 11, w = 0, l = 2))
结果输出如下:
November 2015
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
November 2015
Mon Tue Wed Thu Fri Sat Sun
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
November 2015
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
蔡军生 QQ:9073204 深圳
顶 0 踩 0
我的同类文章
猜你在找
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场