python中time,datetime模块学习

一、time模块

时间表示方法:

时间戳类型:time.time()

数组的类型即struct_time:time.localtime()

时间戳与struct_time的相互转换:

时间戳-->struct_time:gmtime()

struct_time-->时间戳:mktime()

struct_time类型与字符型的相互转换:

struct_time 转换成字符串:strftime()

字符串转换成struct_time:strptime()

二、datetime模块

datetime.datetime:表示日期时间。

通time模块一样,也提供了strftime与strptime进行datetime类型与字符串的转化

datetime.timedelta:表示时间间隔,即两个时间点之间的长度。

三、time与datetime之间的互相转换

时间戳--->datetime:

datetime-->struct_time:

struct_time-->datetime:

可通过中间状态string完成,也可让struct_time,转化为时间戳,再变为datetime

四、指定日期和时间的加减

timedelta(weeks=0, days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0)


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容