python基础语法19-calendar模块

一、简介
有了time及datetime模块,再结合日历(Calendar)模块就可以更好的覆盖到时间处理的各个方面的应用。日历模块主要是用于处理日历及星期相关操作。
calendar模块的内置函数如下:
序号           函数及描述
1    calendar.calendar(year,w=2,l=1,c=6) 返回一个多行字符串格式的 year 年年历,3 个月一行,间隔距离为 c。 每日宽度间隔为w字符。每行长度为 21* W+18+2* C。l 是每星期行数。
2    calendar.firstweekday( ) 返回当前每周起始日期的设置。默认情况下,首次载入 calendar 模块时返回 0,即星期一。
3    calendar.isleap(year) 是闰年返回 True,否则为 False。
4    calendar.leapdays(y1,y2) 返回在Y1,Y2两年之间的闰年总数。
5    calendar.month(year,month,w=2,l=1)  返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7* w+6。l是每星期的行数。
6    calendar.monthcalendar(year,month)  返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。
7    calendar.monthrange(year,month)  返回两个整数。第一个是该月的星期几,第二个是该月有几天。星期几是从0(星期一)到 6(星期日)。
8    calendar.prcal(year, w=0, l=0, c=6, m=3)  相当于 print(calendar.calendar(year, w=0, l=0, c=6, m=3))。
9    calendar.prmonth(theyear, themonth, w=0, l=0)  相当于 print(calendar.month(theyear, themonth, w=0, l=0))。
10    calendar.setfirstweekday(weekday)  设置每周的起始日期码。0(星期一)到6(星期日)。
11    calendar.timegm(tupletime)  和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间戳(1970纪元后经过的浮点秒数)。
12    calendar.weekday(year,month,day)  返回给定日期的日期码。0(星期一)到6(星期日)。月份为 1(一月) 到 12(12月)。
二、calendar模块使用示例
import calendar,time
1.返回一个年历,3个月为1行,每日宽度间隔为2个字符,每行间隔距离为1,4是每星期行数
 print(calendar.calendar(2022,2,1,4))
 结果为:

2.calendar.firstweekday()
 print(calendar.firstweekday())#结果为0
3.calendar.isleap(year)判断是否闰年
 print(calendar.isleap(2022))#结果为False
4.calendar.leapdays(y1,y2)返回y1到y2年份之间闰年总数
 print(calendar.leapdays(2000, 2022))#结果为6
5.calendar.month(year,month,w,l)返回year年month月日历 w为每日间隔宽度,l为每星期的行数
print(calendar.month(2022,12,2,1))
结果为:
   December 2022
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 31
6.calendar.monthcalendar(year,month) 返回单层嵌套列表
print(calendar.monthcalendar(2022,12))
结果为:
[[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, 31, 0]]
7.calendar.monthrange(year,month) 返回两个整数
 print(calendar.monthrange(2022, 12))#结果为(3, 31)
8.calendar.prcal(year, w=0, l=0, c=6, m=3) 自带打印输入日历
print(calendar.prcal(2022,2,1,4))
结果为:

9.calendar.prmonth(theyear, themonth, w=0, l=0)
print(calendar.prmonth(2022,3))
 结果为:
 March 2022
 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 31
 None
10.calendar.setfirstweekday(weekday)
calendar.setfirstweekday(1)
c1 = calendar.firstweekday()
print(c1)#结果为1
11.calendar.timegm(tupletime)
print(calendar.timegm((2022,12,23,9,25,33,4,357,0)))#结果为1671787533
12.calendar.weekday(year,month,day)
print(calendar.weekday(2022, 12, 23))#结果为4

 

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
作者和贡献者 I. 入门指引 1. 简介 2. 简明教程 II. 安装与配置 3. 安装前需要考虑的事项 4. Unix 系统下的安装 5. Mac OS X 系统下的安装 6. Windows 系统下的安装 7. PECL 扩展库安装 8. 还有问题? 9. 运行时配置 III. 语言参考 10. 基本语法 11. 类型 12. 变量 13. 常量 14. 表达式 15. 运算符 16. 流程控制 17. 函数 18. 类与对象(PHP 4) 19. 类与对象(PHP 5) 20. 异常处理 21. 引用的解释 IV. 安全 22. 简介 23. 总则 24. 以 CGI 模式安装时 25. 以 Apache 模块安装时 26. 文件系统安全 27. 数据库安全 28. 错误报告 29. 使用 Register Globals 30. 用户提交的数据 31. 魔术引号 32. 隐藏 PHP 33. 保持更新 V. 特点 34. 用 PHP 进行 HTTP 认证 35. cookies 36. 会话 37. 处理 XForms 38. 文件上传处理 39. 使用远程文件 40. 连接处理 41. 数据库永久连接 42. 安全模式 43. PHP 的命令行模式 VI. 函数参考 I. .NET 函数 II. Advanced PHP debugger III. Alternative PHP Cache IV. Apache 特有函数 V. Array 数组函数 VI. Aspell 函数(已废弃) VII. BC math 高精度数学函数 VIII. Bzip2 压缩函数 IX. Calendar 日历函数 X. CCVS API Functions [deprecated] XI. Character Type Functions XII. Classes/Objects 类/对象函数 XIII. Classkit Functions XIV. ClibPDF Functions XV. COM 和 .Net(Windows)函数 XVI. Crack Functions XVII. Credit Mutuel CyberMUT functions XVIII. CURL, Client URL Library Functions XIX. Cybercash Payment Functions XX. Cyrus IMAP administration Functions XXI. Database (dbm-style) Abstraction Layer Functions XXII. Date/Time 日期/时间函数 XXIII. DB++ Functions XXIV. dBase Functions XXV. DBM Functions [deprecated] XXVI. dbx Functions XXVII. Direct IO Functions XXVIII. Directory 目录函数 XXIX. DOM Functions XXX. DOM XML Functions XXXI. Error Handling and Logging Functions XXXII. Exif Functions XXXIII. File Alteration Monitor Functions XXXIV. filePro Functions XXXV. Filesystem 文件系统函数 XXXVI. Firebird/InterBase Functions XXXVII. Firebird/Interbase Functions (PDO_FIREBIRD) XXXVIII. Forms Data Format Functions XXXIX. FriBiDi Functions XL. FrontBase Functions XLI. FTP 函数 XLII. Function Handling Functions XLIII. Gettext XLIV. GMP Functions XLV. GNU Readline XLVI. GNU Recode Functions XLVII. HTTP 函数 XLVIII. Hyperwave API Functions XLIX. Hyperwave Functions L. IBM DB2, Cloudscape and Apache Derby Functions LI. ICAP Functions [deprecated] LII. iconv Functions LIII. ID3 Functions LIV. IIS Administration Functions LV. Image 图像函数 LVI. IMAP, POP3 and NNTP Functions LVII. Informix Functions LVIII. Ingres II Functions LIX. IRC Gateway Functions LX. KADM5 LXI. LDAP Functions LXII. libxml Functions LXIII. Lotus Notes Functions LXIV. LZF Functions LXV. Mail Functions LXVI. mailparse Functions LXVII. Math 数学函数 LXVIII. MaxDB PHP Extension LXIX. MCAL Functions LXX. Mcrypt Encryption Functions LXXI. MCVE Payment Functions LXXII. Memcache Functions LXXIII. Mhash Functions LXXIV. Microsoft SQL Server and Sybase Functions (PDO_DBLIB) LXXV. Microsoft SQL Server Functions LXXVI. Mimetype Functions LXXVII. Ming functions for Flash LXXVIII. Miscellaneous Functions LXXIX. mnoGoSearch Functions LXXX. Mohawk Software Session Handler Functions LXXXI. mSQL Functions LXXXII. Multibyte String Functions LXXXIII. muscat Functions LXXXIV. MySQL 函数 LXXXV. MySQL Functions (PDO_MYSQL) LXXXVI. MySQL Improved Extension LXXXVII. Ncurses Terminal Screen Control Functions LXXXVIII. Network Functions LXXXIX. Net_Gopher XC. NSAPI-specific Functions XCI. Object Aggregation/Composition Functions XCII. Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Oracle 函数 XCIX. Oracle Functions (PDO_OCI) C. Oracle 函数(已废弃) CI. Output Control 输出控制函数 CII. Ovrimos SQL Functions CIII. Paradox File Access CIV. Parsekit Functions CV. PDF functions CVI. PDO Functions CVII. PHP / Java Integration CVIII. PHP bytecode Compiler CIX. PHP Options&Information CX. POSIX Functions CXI. PostgreSQL 数据库函数 CXII. PostgreSQL Functions (PDO_PGSQL) CXIII. PostgreSQL Session Save Handler CXIV. PostScript document creation CXV. Printer Functions CXVI. Process Control Functions CXVII. Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar Functions CXXII. Perl 兼容正则表达式函数 CXXIII. POSIX 扩展正则表达式函数 CXXIV. runkit Functions CXXV. SDO Functions CXXVI. SDO Relational Data Access Service Functions CXXVII. SDO XML Data Access Service Functions CXXVIII. Secure Shell2 Functions CXXIX. Semaphore, Shared Memory and IPC Functions CXXX. SESAM Database Functions CXXXI. Session Handling Functions CXXXII. Shared Memory Functions CXXXIII. Shockwave Flash Functions CXXXIV. SimpleXML functions CXXXV. SNMP 函数 CXXXVI. SOAP Functions CXXXVII. Socket Functions CXXXVIII. SQLite Functions CXXXIX. SQLite Functions (PDO_SQLITE) CXL. Standard PHP Library (SPL) Functions CXLI. Stream Functions CXLII. String 字符串处理函数 CXLIII. Sybase Functions CXLIV. TCP Wrappers Functions CXLV. Tidy Functions CXLVI. Tokenizer Functions CXLVII. Unicode Functions CXLVIII. URL 函数 CXLIX. Variable 变量函数 CL. Verisign Payflow Pro Functions CLI. vpopmail Functions CLII. W32api 函数 CLIII. WDDX Functions CLIV. xattr Functions CLV. xdiff Functions CLVI. XML 语法解析函数 CLVII. XML-RPC 函数 CLVIII. XMLReader functions CLIX. XSL functions CLX. XSLT Functions CLXI. YAZ Functions CLXII. YP/NIS Functions CLXIII. Zip File Functions (Read Only Access) CLXIV. Zlib Compression Functions VII. PHP 和 Zend 引擎内部资料 44. PHP 扩展库编程 API 指南 45. Zend API:深入 PHP 内核 46. 扩展 PHP 3 VIII. FAQ:常见问题 47. 一般信息 48. 邮件列表 49. 获取 PHP 50. 数据库问题 51. 安装常见问题 52. 编译问题 53. 使用 PHP 54. PHP 和 HTML 55. PHP 和 COM 56. PHP 和其它语言 57. 从 PHP/FI 2 移植到 PHP 3 58. 从 PHP 3 移植到 PHP 4 59. 从 PHP 4 移植到 PHP 5 60. 杂类问题 IX. 附录 A. PHP 及其相关工程的历史 B. 从 PHP 4 移植到 PHP 5 C. 从 PHP 3 移植到 PHP 4 D. 从 PHP/FI 2 移植到 PHP 3 E. PHP 的调试 F. 配置选项 G. php.ini 配置选项 H. 扩展库分类 I. 函数别名列表 J. 保留字列表 K. 资源类型列表 L. 支持的协议/封装协议列表 M. 可用过滤器列表 N. 所支持的套接字传输器(Socket Transports)列表 O. PHP 类型比较表 P. 解析器代号列表 Q. 关于本手册 R. 开放出版许可协议 S. 函数索引

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

春风抚微霞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值