11 python获取系统时间之time库的使用

11 python获取系统时间之time库的使用

获取时间

import time
time.time() #获取从1970.1.1 0:00到现在有多少秒, 是一个浮点数
time.ctime() 这个函数可以获取一个易于读取的时间格式,格式为字符串格式
time.gmtime() 返回计算机程序可处理的时间格式,struct_time格式,是一个结构体

时间格式化

11 python获取系统时间之time库的使用_第1张图片
11 python获取系统时间之time库的使用_第2张图片
11 python获取系统时间之time库的使用_第3张图片
strptime()函数和strtime()函数是互补关系,他将一段字符串变成时间

11 python获取系统时间之time库的使用_第4张图片

程序计时

测量时间 perf_counter()
产生时间 sleep()
11 python获取系统时间之time库的使用_第5张图片

注意这里计算的时间差

11 python获取系统时间之time库的使用_第6张图片

你可能感兴趣的:(python)