首页 技术 正文
技术 2022年11月10日
0 收藏 511 点赞 3,989 浏览 1057 个字
#python中的calendarimport calendar#返回指定年的某月
def get_month(year, month):
return calendar.month(year, month)#返回指定年的日历
def get_calendar(year):
return calendar.calendar(year)#判断某一年是否为闰年,如果是,返回True,如果不是,则返回False
def is_leap(year):
return calendar.isleap(year)#返回某个月的weekday的第一天和这个月的所有天数
def get_month_range(year, month):
return calendar.monthrange(year, month)#返回某个月以每一周为元素的序列
def get_month_calendar(year, month):
return calendar.monthcalendar(year, month)def main():
year = 2013
month = 8
test_month = get_month(year, month)
print(test_month)
print('#' * 50)
#print(get_calendar(year))
print('{0}这一年是否为闰年?:{1}'.format(year, is_leap(year)))
print(get_month_range(year, month))
print(get_month_calendar(year, month))if __name__ == '__main__':
main()
最常用的time.time()返回的是一个浮点数,单位为秒。但strftime处理的类型是time.struct_time,实际上是一个tuple。strptime和localtime都会返回这个类型。>>> import time
>>> t = time.time()
>>> t
1202872416.4920001
>>> type(t)
<type 'float'>
>>> t = time.localtime()
>>> t
(2008, 2, 13, 10, 56, 44, 2, 44, 0)
>>> type(t)
<type 'time.struct_time'>
>>> time.strftime('%Y-%m-%d', t)
'2008-02-13'
>>> time.strptime('2008-02-14', '%Y-%m-%d')
(2008, 2, 14, 0, 0, 0, 3, 45, -1)
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898