#python中的calendar

import 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)

最新文章

  1. 配置Hibernate二级缓存时,不能初始化RegionFactory的解决办法
  2. HDU 2841 Visible Trees 数论+容斥原理
  3. ADO.NET中的TransactionScope何时需要启用MSTDC(分布式事务管理)
  4. webtest 文章
  5. Quartz Scheduler(2.2.1) - Working with SchedulerListeners
  6. Python3.4 多线程
  7. Mysql导出导入乱码问题解决
  8. NSTimer内存方面的探究
  9. oracle10g遇到ORA-16038日志无法归档问题
  10. Memcached操作以及用法
  11. 老李推荐:第6章7节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-注入按键事件实例
  12. JS实现鼠标移上去图片停止滚动移开恢复滚动效果
  13. MySQL连接问题【如何解决MySQL连接超时关闭】
  14. 关于Android 7.0(API24)相机的问题汇总
  15. C#中判断DataReader是否为空的代码
  16. centos7修改网卡名称为eth0-技术流ken
  17. Sql Server 按格式输出日期
  18. Liferay7 BPM门户开发之25: Liferay7应用程序配置(APPLICATION CONFIGURATION)
  19. SpringBank 开发日志 一种简单的拦截器设计实现
  20. 在java中构建json对象,返回给前端页面

热门文章

  1. 替换word中的数据,并给导入word的图片添加水印
  2. 记录一次C#的asyn和await
  3. MIT线性代数:2.消元法
  4. 前端与算法 leetcode 283. 移动零
  5. NOIP模拟 20
  6. 1. 彤哥说netty系列之开篇(有个问卷调查)
  7. 易初大数据 2019年11月7日 spss 王庆超
  8. python的基础认识
  9. 快速搭建Jenkins集群
  10. WPF CefSharp 爬虫