5.2 calendar--通用日期的相关函数(3)
prmonth(theyear, themonth, w=0, l=0)
打印指定年和月的日历。格式与formatmonth()函数一样。
样例:
#python 3.4
import calendar
cal = calendar.TextCalendar(0)
cal.prmonth(2015, 11)
cal.prmonth(2015, 11, w = 5)
cal.prmonth(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
formatyear(theyear, w=2, l=1, c=6, m=3)
返回指定年的全部月的日历。參数w是给示列与列之间宽度。參数l是表示行与与之间宽度,參数m是表示月与月之间的宽度。
样例:
#python 3.4
import calendar
cal = calendar.TextCalendar(0)
print(cal.formatyear(2015))
结果输出例如以下:
2015
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30
31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30
pryear(theyear, w=2, l=1, c=6, m=3)
打印指定年的日历。格式按formatyear()函数一样。
样例:
#python 3.4
import calendar
cal = calendar.TextCalendar(0)
cal.pryear(2015)
结果输出例如以下:
2015
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30
31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30
class calendar.HTMLCalendar(firstweekday=0)
这是创建一个生成HTML内容的日历。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal)
输出结果例如以下:
<calendar.HTMLCalendar object at 0x02CA0E30>
HTMLCalendar类的实例方法例如以下:
formatmonth(theyear, themonth, withyear=True)
返回指定年和月的HTML表格的日历。假设withyear为True在表头的标题里包含年份,否则仅仅有月份作为标题。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal.formatmonth(2015, 11))
结果输出例如以下:
<table border="0" cellpadding="0" cellspacing="0" class="month">
<tr><th colspan="7" class="month">November 2015</th></tr>
<tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
<tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="sun">1</td></tr>
<tr><td class="mon">2</td><td class="tue">3</td><td class="wed">4</td><td class="thu">5</td><td class="fri">6</td><td class="sat">7</td><td class="sun">8</td></tr>
<tr><td class="mon">9</td><td class="tue">10</td><td class="wed">11</td><td class="thu">12</td><td class="fri">13</td><td class="sat">14</td><td class="sun">15</td></tr>
<tr><td class="mon">16</td><td class="tue">17</td><td class="wed">18</td><td class="thu">19</td><td class="fri">20</td><td class="sat">21</td><td class="sun">22</td></tr>
<tr><td class="mon">23</td><td class="tue">24</td><td class="wed">25</td><td class="thu">26</td><td class="fri">27</td><td class="sat">28</td><td class="sun">29</td></tr>
<tr><td class="mon">30</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr>
</table>
formatyear(theyear, width=3)
返回指定年的一年日历的HTML表格,參数width是指定一个月几行排列。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal.formatyear(2015))
结果输出例如以下:
<table border="0" cellpadding="0" cellspacing="0" class="year">
<tr><th colspan="3" class="year">2015</th></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month">
<tr><th colspan="7" class="month">January</th></tr>
<tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
...
formatyearpage(theyear, width=3, css='calendar.css', encoding=None)
返回指定年的一年HTML完整网页的日历。參数width是指定一个月排列多少行。參数css是指定页面使用的类型,參数encoding是指定网页的编码。默认是系统编码。
样例:
#python 3.4
import calendar
cal = calendar.HTMLCalendar(0)
print(cal.formatyearpage(2015))
结果输出例如以下:
b'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n<link rel="stylesheet" type="text/css" href="calendar.css" />\n<title>Calendar for 2015</title>\n</head>\n<body>\n<table border="0" cellpadding="0" cellspacing="0" class="year">\n<tr><th colspan="3" class="year">2015</th></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month">\n<tr><th colspan="7" class="month">January</th></tr>\n<tr><th class="mon">Mon</th><th class="tue">
...
1</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr>\n</table>\n</td></tr></table></body>\n</html>\n'
class calendar.LocaleTextCalendar(firstweekday=0, locale=None)
这是一个TextCalendar的子类,通过构造函数来设定不同地区的日历。
class calendar.LocaleHTMLCalendar(firstweekday=0, locale=None)
这是一个HTMLCalendar的子类,通过构造函数来设定不同地区的日历。
蔡军生 QQ:9073204 深圳
5.2 calendar--通用日期的相关函数(3)的更多相关文章
- WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 日历控 ...
- ASP.NET Repeater 绑定 DropDownList Calendar 选择日期
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- HDOJ(HDU) 2133 What day is it(认识下Java的Calendar类---日期类)
Problem Description Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me wha ...
- Calendar计算日期
一.周六三月进去.星期天 Calendar calendar=Calendar.getInstance();//当前日期 Calendar calendar2=Calendar.getInstance ...
- 【转】WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要内容: 日历控件Calendar自定义样式: 日期控件DatePicker自定 ...
- [Swift实际操作]七、常见概念-(7)日历Calendar和日期组件DateComponents
本文将为你演示日历和日期组件的使用.通过日历的日期部件,可以获得日期的各个部分. 首先引入需要用到的界面工具框架 import UIKit 初始化一个日期对象,其值为当前的日期. let dt = D ...
- POJ2080:Calendar(计算日期)
Calendar Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12842 Accepted: 4641 Descrip ...
- java 利用Calendar进行日期更改
//建立1个日期实例 Date tomorrow= new Date(); //获取今天日期 Date nowDate = Calendar.getInstance().getTime(); // 构 ...
- MySQL 日期时间相关函数整理
-- 为日期增加一个时间间隔:date_add() SELECT NOW(); YEAR); MONTH); DAY); HOUR); MINUTE); SECOND); MICROSECOND); ...
- 使用Calendar增加日期
/** * @Description: 当前日期加上n个月返回long date */ public static long getLongDateAddMonth(int n){ Calendar ...
随机推荐
- cf 843 D Dynamic Shortest Path [最短路+bfs]
题面: 传送门 思路: 真·动态最短路 但是因为每次只加1 所以可以每一次修改操作的时候使用距离分层的bfs,在O(n)的时间内解决修改 这里要用到一个小技巧: 把每条边(u,v)的边权表示为dis[ ...
- bootstrap之常见组件应用1
bootstrap中,常见的组件有很多,比如按钮,输入框,导航条,巨幕,面板等.这次根据对bootstrap的一系列学习进行总结. 按钮:button <button type="bu ...
- pat 甲级 1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...
- pat 甲级 1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- BZOJ 3513: [MUTC2013]idiots
3513: [MUTC2013]idiots Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 476 Solved: 162[Submit][Stat ...
- 【CF1073A】Diverse Substring(签到)
题意:给定一个由小写字母组成的串,要求找出一个子串使得其中出现最多的字母不超过它长度的一半下取整 n<=1e3 思路: #include<cstdio> #include<cs ...
- C#执行CMD命令并接收返回结果的实现方法
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using ...
- springBoot 打成jar包
1.一种方式通过cmd 窗口进行打包 配置maven 环境变量 进入到项目中 运行 mvn clean 然后运行mvn package 进行打包 2.通过idea 进行打包 (1)pom 中安装打包 ...
- AC日记——K-th Number poj 2104
K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 52348 Accepted: 17985 Ca ...
- 牛客网 Wannafly挑战赛8 B.LBJX的三角形
B-LBJX的三角形 链接:https://www.nowcoder.com/acm/contest/57/B来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K, ...