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

python calendar 时间处理类库的更多相关文章

  1. python语法------时间函数

    1.导入函数库: import time 获取格式化的时间 你可以根据需求选取各种格式,但是最简单的获取可读的时间模式的函数是asctime(): #!/usr/bin/python # -*- co ...

  2. python中时间的基本使用

    格式化日期 我们可以使用 time 模块的 strftime 方法来格式化日期,: time.strftime(format[, t]) #!/usr/bin/python # -*- coding: ...

  3. python datetime 时间日期处理小结

    python datetime 时间日期处理小结 转载请注明出处:http://hi.baidu.com/leejun_2005/blog/item/47f340f1a85b5cb3a50f5232. ...

  4. python 日期 & 时间

    1. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 2. 时间间隔是以秒为单位的浮点小数. 3. 每个时间戳都以自从1970年1月1日午夜(历元)经过了多长 ...

  5. Python日期时间Date/Time

    Python程序可以处理多种方式的日期和时间.日期格式之间的转换是一种常见计算机的杂活. Python的时间和日历模块,能帮助处理日期和时间. Tick是什么? 为时间间隔,以秒为单位的浮点数.从“新 ...

  6. 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码

    本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...

  7. Python 常见时间处理

    Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见的功能. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时间间隔是以秒为单位的浮点小数. ...

  8. python 的时间与日期

    显示当前日期: import time print time.strftime('%Y-%m-%d %A %X %Z',time.localtime(time.time())) 或者 你也可以用: p ...

  9. Python 日期时间处理模块学习笔记

    来自:标点符的<Python 日期时间处理模块学习笔记> Python的时间处理模块在日常的使用中用的不是非常的多,但是使用的时候基本上都是要查资料,还是有些麻烦的,梳理下,便于以后方便的 ...

随机推荐

  1. LeetCode 二叉树的层次遍历

    第102题 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如: 给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 ...

  2. MIT线性代数:3.矩阵相乘

  3. 消息中心 - Laravel的Redis队列(一)

    前言 Laravel的队列可以用在轻量级的队列需求中.比如我们系统中的短信.邮件等功能,这些功能有一些普遍的特征,异步.重试.并发控制等.Laravel现在主要支持的队列服务有Null.Sync.Da ...

  4. MongoDB自学------(1)MongoDB4.0安装

    一.环境 操作系统 安装包 安装方式 Ubuntu18.04 mongodb4.0 apt安装 Ubuntu18.04 mongodb4.0 docker安装 二.apt安装 sudo apt-key ...

  5. Microsoft Visual C++ 14.0 is required问题解决

    当我们在windows下安装包或者软件时会出现: Microsoft Visual C++ b'v14.0 is required 错误解决办法 直接下载安装visualstudio: https:/ ...

  6. JVM 中你不得不知的一些参数

    有的同学虽然写了一段时间 Java 了,但是对于 JVM 却不太关注.有的同学说,参数都是团队规定好的,部署的时候也不用我动手,关注它有什么用,而且,JVM 这东西,听上去就感觉很神秘很高深的样子,还 ...

  7. PHP array_multisort实现二维数组排序

    PHP array_multisort实现二维数组排序 参数中的数组被当成一个表的列并以行来进行排序 - 这类似 SQL 的 ORDER BY 子句的功能.第一个数组是要排序的主要数组.数组中的行(值 ...

  8. hashMapp

    原文链接:https://www.iteye.com/topic/539465 Hashmap是一种非常常用的.应用广泛的数据类型,最近研究到相关的内容,就正好复习一下.网上关于hashmap的文章很 ...

  9. 网站搭建-2-本地网站搭建-安装Linux虚拟机/ 安装IIS Windows

    搭建网站-1-域名申请参见公众号 生物信息系统(swxxxt) 首先,已经拥有了一个可以正常使用的域名. 之前买了两年的阿里的服务器,由于是Windows的,最后不了了之了(因为当时找的代码都是lin ...

  10. mybatis什么时候必须指定jdbcType

    #{property,javaType=int,jdbcType=NUMERIC}如果一个列允许 null 值,并且会传递值 null 的参数,就必须要指定 JDBC Type