首页
学习
活动
专区
工具
TVP
发布

Python干货宝典!玩转内置模块:日历模块

Python定义了内置模块calendar它处理与日历相关的操作。

Calendar module允许输出日历(如程序),并提供与日历相关的其他有用功能。

Calendar模块中定义的函数和类使用理想化的日历,当前的公历在两个方向上无限期扩展。

默认情况下,这些日历的周一为一周的第一天,星期日为最后一天。

例1:显示给定月份的日历。

# Python program to display calendar of

# given month of the year

# import module

import calendar

yy = 2017

mm = 11

# display the calendar

print(calendar.month(yy, mm))

产出:

例2:显示给定年份的日历。

# Python code to demonstrate the working of

# calendar() function to print calendar

# importing calendar module

# for calendar operations

import calendar

# using calender to print calendar of year

# prints calendar of 2018

print ("The calender of year 2018 is : ")

print (calendar.calendar(2018, 2, 1, 6))

产出:

class calendar.Calendar :

类创建Calendar对象。Calendar对象提供了几种可用于准备日历数据以进行格式化的方法。

日历类允许根据日期、月份和年份计算各种任务。日历类提供以下方法:

周列表中的条目是天数

class calendar.TextCalendar :

TextCalendar类可用于生成纯文本日历。Python中的TextCalendar类允许您根据需要编辑日历并使用。

class calendar.HTMLCalendar :

HTMLCalendar类可用于生成HTML日历。Python中的HTMLCalendar类允许您根据需要编辑日历并使用。

Simple TextCalendar class :

对于简单的文本日历日历模块提供下列功能:

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20201119A0FCLT00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券